-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapData.py
More file actions
89 lines (68 loc) · 2.35 KB
/
mapData.py
File metadata and controls
89 lines (68 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from pytz import timezone
import json
from urllib.request import urlopen
import time
import datetime
import jsonManipulation as keyManager
########### Weather:
class Maps:
apiKey = ""
location = ""
def __init__(self, apiKey, starting, ending):
self.apiKey = apiKey
self.starting = starting
self.ending = ending
def getMapRouteURL(self, starting = False, ending = False, apiKey = False):
if not starting:
starting = self.starting
if not ending:
ending = self.ending
if not apiKey:
apiKey = self.apiKey
myURL = "https://api.tomtom.com/routing/1/calculateRoute/"
myURL += starting + ":"
myURL += ending
myURL += "/json?routeRepresentation=summaryOnly&routeType=fastest&traffic=true&key=%s" % apiKey
return myURL
def getRoute(self, starting = False, ending = False, apiKey = False):
if not starting:
starting = self.starting
if not ending:
ending = self.ending
if not apiKey:
apiKey = self.apiKey
myURL = self.getMapRouteURL(starting, ending, apiKey)
response = urlopen(myURL)
data_json = json.loads(response.read())
print("Full:", data_json)
print("Routes:", data_json["routes"])
travelTime = data_json["routes"][0]["summary"]["travelTimeInSeconds"]
trafficDelay = data_json["routes"][0]["summary"]["trafficDelayInSeconds"]
print("Delay: ", trafficDelay)
print("Total Time: ", travelTime)
print("")
def getDelay()
myURL = self.getMapRouteURL(starting, ending, apiKey)
response = urlopen(myURL)
trafficDelay = data_json["routes"][0]["summary"]["trafficDelayInSeconds"]
return trafficDelay
def getTotalTime()
myURL = self.getMapRouteURL(starting, ending, apiKey)
response = urlopen(myURL)
trafficDelay = data_json["routes"][0]["summary"]["travelTimeInSeconds"]
return trafficDelay
if __name__ == "__main__":
key = keyManager.grabKey("Maps")
slbRosharon = "29.369761491768053,-95.44032360371638"
circleAtHermann = "29.717824428555325,-95.38149686040018"
westminster = "33.847790796962194,-84.43337746636308"
ATL = "33.64076407111493,-84.44645867900734"
oraclePark = "37.77850485799018,-122.38936912400277"
endor = "37.8288194798984,-122.4861098025627"
oakland = "37.80470730494777,-122.2713473805796"
# Texas locations...
defaultStarting = oakland
defaultEnding = oraclePark
mapManager = Maps(key, defaultStarting, defaultEnding)
print(mapManager.getMapRouteURL())
mapManager.getRoute()