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

Use seconds since midnight for Shuttles #69

Merged
merged 2 commits into from
Apr 28, 2016
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,11 @@ http://map.utoronto.ca

--------------------------------------------------------------------------------

### Shuttle
### Shuttles

##### Class name
```python
uoftscrapers.Shuttle
uoftscrapers.Shuttles
```

##### Scraper source
Expand All @@ -583,7 +583,7 @@ https://m.utm.utoronto.ca/shuttle.php
"location": String,
"building_id": String,
"times": [{
"time": String,
"time": Number,
"rush_hour": Boolean,
"no_overload": Boolean
}]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'uoftscrapers.scrapers.exams',
'uoftscrapers.scrapers.athletics',
'uoftscrapers.scrapers.parking',
'uoftscrapers.scrapers.shuttle',
'uoftscrapers.scrapers.shuttles',
'uoftscrapers.scrapers.events',
'uoftscrapers.scrapers.libraries'
],
Expand Down
2 changes: 1 addition & 1 deletion uoftscrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from .scrapers.parking import Parking

from .scrapers.shuttle import Shuttle
from .scrapers.shuttles import Shuttles

from .scrapers.events import Events

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import time


class Shuttle:
class Shuttles:
"""A scraper for UofT's shuttle bus schedule.
The schedule is located at https://m.utm.utoronto.ca/shuttle.php.
The schedule is located at https://m.utm.utoronto.ca/Shuttles.php.
"""

host = 'https://m.utm.utoronto.ca/shuttleByDate.php?year=%s&month=%s&day=%s'
Expand All @@ -36,8 +36,8 @@ def scrape(location='.', month=None):
'Fetching schedules for {0}-{1}-01 to {0}-{1}-{2}.'.format(year, month, days))

for day in range(1, days + 1):
html = Scraper.get(Shuttle.host % (year, month, day))
schedule = Shuttle.parse_schedule_html(html)
html = Scraper.get(Shuttles.host % (year, month, day))
schedule = Shuttles.parse_schedule_html(html)

Scraper.save_json(schedule, location, schedule['date'])

Expand Down Expand Up @@ -73,18 +73,20 @@ def parse_schedule_html(html):
time_rush_hour = 'rush hour' in _route_time_text
time_no_overload = 'no overload' in _route_time_text

military_time = time.strftime('%H:%M %p',
time.strptime(_route_time_clean, '%I:%M %p'))[:-3]
military_time = [int(x) for x in military_time.split(':')]

seconds = military_time[0] * 3600 + military_time[1] * 60

times.append(OrderedDict([
('time', '%sT%s:00-04:00' % (
date,
time.strftime('%H:%M %p', time.strptime(
_route_time_clean, '%I:%M %p'))[:-3]
)),
('time', seconds),
('rush_hour', time_rush_hour),
('no_overload', time_no_overload)
]))

# TODO: fetch this dynamically
route_building_id = Shuttle.building_ids[route_location] if route_location in Shuttle.building_ids else ''
route_building_id = Shuttles.building_ids[route_location] if route_location in Shuttles.building_ids else ''

route_stops = OrderedDict([
('location', route_location),
Expand Down