Post

Replies

Boosts

Views

Activity

Reply to Applescript to estimate driving times
I wrote this a couple years ago using Python, using Google Maps, hoping to find a good time to miss traffic. (Spoiler: There isn't one at a reasonable hour.) I hope it is ok to post a Google-centric solution. Enjoy! #!/usr/bin/python import urllib.request, json, datetime, pytz url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&departure_time=now&origins=Denver+CO&destinations=Boulder+C O&key=putYourKeyHere" response = urllib.request.urlopen(url) data = json.loads(response.read()) t = datetime.datetime.now() now_utc = datetime.datetime.now(pytz.timezone('US/Mountain')) t = now_utc.astimezone(pytz.timezone('US/Mountain')) f = open('travelTime.csv','a') distanceT=data['rows'][0]['elements'][0]['distance']['text'] distanceV=data['rows'][0]['elements'][0]['distance']['value'] durationT=data['rows'][0]['elements'][0]['duration_in_traffic']['text'] durationV=data['rows'][0]['elements'][0]['duration_in_traffic']['value'] f.write("%s,%s,%s,%s,%s\n" % (t.strftime("%Y-%m-%d %H:%M:%S"), distanceT, distanceV, durationT, durationV)) f.close()
Nov ’23