Last active
September 21, 2022 12:56
-
-
Save chrisboyle/c00d65eb8119b9f0a7309ed2afd4ce24 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/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