Skip to content

Instantly share code, notes, and snippets.

@eoghanmurray
Last active December 17, 2015 17:39
Show Gist options
  • Save eoghanmurray/5647699 to your computer and use it in GitHub Desktop.
Save eoghanmurray/5647699 to your computer and use it in GitHub Desktop.
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
@eoghanmurray
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment