Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mobhis parsing #763

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions pybikes/mobhis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def update(self, scraper=None):
latlngs = re.findall(r'var marker = L\.marker\(\[(-?\d+\.\d+), (-?\d+\.\d+)\]', data)
infos = re.findall(r'marker.bindPopup\("(.*)"\)', data)
stations = zip(latlngs, infos)

self.stations = list(map(lambda i: MobhisStation(*i), stations))


Expand All @@ -54,18 +53,18 @@ def __init__(self, coords, info):

self.name = elems.pop(0)

# find ints on remaining elements
elems = list(map(lambda s: re.search(r'\d+', s).group(), elems))
fuzzle = " ".join(elems)
bikes = re.findall(r'(\d+) bikes', fuzzle)
slots = re.findall(r'(\d+) vagas', fuzzle)

# some systems have data for kid-sized bikes and spaces
if len(elems) > 2:
bikes, bikes_kids, free, free_kids = elems
# there's kids bikes info
if len(bikes) > 1 and len(slots) > 1:
self.extra.update({
'kid_bikes': int(bikes_kids),
'kid_slots': int(free_kids),
'kid_bikes': int(bikes[1]),
'kid_slots': int(slots[1]),
})
else:
bikes, free = elems

self.bikes = int(bikes)
self.free = int(free)
bikes, free = int(bikes[0]), int(slots[0])

self.bikes = bikes
self.free = free
Loading