Skip to content

Instantly share code, notes, and snippets.

@chrisboyle
Last active September 21, 2022 12:56
Show Gist options
  • Select an option

  • Save chrisboyle/c00d65eb8119b9f0a7309ed2afd4ce24 to your computer and use it in GitHub Desktop.

Select an option

Save chrisboyle/c00d65eb8119b9f0a7309ed2afd4ce24 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import googlemaps
from datetime import datetime
# https://console.cloud.google.com/google/maps-apis/start
key = os.getenv('GOOGLE_MAPS_API_KEY')
gmaps = googlemaps.Client(key = key)
result = gmaps.directions('Thornhill Park & Ride, Oxford', 'City Centre, Oxford', mode = 'transit', departure_time = datetime.now(), alternatives = True, transit_routing_preference = 'less_walking')
first_steps = [r['legs'][0]['steps'][0] for r in result]
initial_transits = [s['transit_details'] for s in first_steps if 'transit_details' in s]
for t in sorted(initial_transits, key = lambda t: t['departure_time']['value']):
print('%-7s %-9s %-32s' % (t['departure_time']['text'], t['line']['short_name'], t['headsign']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment