Skip to content

Instantly share code, notes, and snippets.

@arnaudmorin
Created October 7, 2015 09:32
Show Gist options
  • Save arnaudmorin/55f788370cc3df7ffae1 to your computer and use it in GitHub Desktop.
Save arnaudmorin/55f788370cc3df7ffae1 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import unirest
from pprint import pprint as pp
import xml.etree.ElementTree as xml
from datetime import datetime
from time import sleep
base_url = "https://www.waze.com/row-RoutingManager/routingRequest?"
from_y = "48.32957"
from_x = "-1.62017"
to_y = "48.12744"
to_x = "-1.62726"
def travelTime(at):
params = {
"from": "x:{} y:{}".format(from_x,from_y),
"to": "x:{} y:{}".format(to_x,to_y),
#"returnJSON": "true",
#"returnGeometries": "false",
#"returnInstructions": "false",
"timeout": 60000,
"nPaths": 1,
"at": at,
}
response = unirest.get(base_url, params=params)
dom = xml.fromstring(response.body)
#route = dom.find('route')
summary = dom.find("summary")
#pp(xml.dump(summary))
return int(summary.get("time"))
def computeAt(day, hour, min):
# This is now
time1 = datetime.now()
# This is the same day but with different hour & minute
time2 = time1.replace(hour=hour, minute=min)
# Delta
timeDelta = time2 - time1
# Delta in min
return int(timeDelta.total_seconds()/60)
if __name__ == "__main__":
pp("Maintenant: {}".format(travelTime(0)/60))
pp(" {:2}H{:2} : {:4} min".format(0,30,travelTime(computeAt(datetime.now().day,0,30))/60))
for d in range(5,11):
pp("{}".format(datetime.now().replace(day=d).strftime("%A")))
for h in range (7,9):
for m in range (0,60,5):
sleep(1)
pp(" {:2}H{:2} : {:4} min".format(h,m,travelTime(computeAt(d,h,m))/60))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment