Last active
December 17, 2015 17:39
-
-
Save eoghanmurray/5647699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fd = Feed(local_gtfs_zip) | |
try: | |
fd.read_table('frequencies.txt') | |
except (KeyError, IOError) as e: | |
pass | |
else: | |
raise Exception('need to handle frequency based schedules') | |
trips_by_route = defaultdict(list) | |
for r in fd.read_table('trips.txt'): | |
trips_by_route[r.route_id].append(r) | |
stop_times_by_trip = defaultdict(list) | |
for r in fd.read_table('stop_times.txt'): | |
stop_times_by_trip[r.trip_id].append(r) | |
calendar_exceptions = defaultdict(list) | |
for r in fd.read_table('calendar_dates.txt'): | |
calendar_exceptions[r.service_id].append(r) | |
# etc. | |
for route_row in fd.read_table('routes.txt'): | |
route_id = route_row.route_id | |
route_desc = route_row.route_short_name or route_row.route_long_name | |
tables = [] | |
stops = set() | |
for trip_row in trips_by_route[route_id]: | |
stop_times = stop_times_by_trip[trip_row.trip_id] | |
stop_ids = [st.stop_id for st in stop_times] | |
# now I store data in 'tables' similar to a timetable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used with https://github.com/eoghanmurray/gtfs-sql/blob/master/gtfs/feed.py