-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
58 lines (45 loc) · 1.39 KB
/
script.py
File metadata and controls
58 lines (45 loc) · 1.39 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
#/usr/bin/python3
import requests
import googlemaps
import json
JSON_OUTPUT = "teams.js"
EVENTNAME = "2017marea"
gmaps = googlemaps.Client(key='REDACTED')
url = "https://www.thebluealliance.com/api/v2/event/{}/teams".format(EVENTNAME)
headers = {'X-TBA-App-Id':'4761:2017mareaMap:1'}
r = requests.get(url, headers=headers)
myjson = r.json()
event = gmaps.geocode('62 Oakland Rd, Reading, MA 01867')[0]["geometry"]["location"]
# Gather geocoding results for each team address. And determine bounds of all teams.
minlat = event["lat"]
minlng = event["lng"]
maxlat = minlat
maxlng = minlng
for team in myjson:
geocode_result = gmaps.geocode(team["location"])[0]
team["position"] = geocode_result["geometry"]["location"]
lat = geocode_result["geometry"]["location"]["lat"]
lng = geocode_result["geometry"]["location"]["lng"]
if lat > maxlat:
maxlat = lat
elif lat < minlat:
minlat = lat
if lng > maxlng:
maxlng = lng
elif lat < minlng:
minglng = lng
boundsmin = {"lat": minlat, "lng": minlng}
boundsmax = {"lat": maxlat, "lng": maxlng}
with open(JSON_OUTPUT, 'w') as myfile:
myfile.write("teams = ")
json.dump(myjson, myfile) # Save the results.
myfile.write(";")
myfile.write("event = ")
json.dump(event, myfile)
myfile.write(";")
myfile.write("boundsmin = ")
json.dump(boundsmin, myfile)
myfile.write(";")
myfile.write("boundsmax = ")
json.dump(boundsmax, myfile)
myfile.write(";")