aboutsummaryrefslogtreecommitdiff
path: root/dev/utah
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-06-06 10:11:12 -0600
committerMelody Horn <melody@boringcactus.com>2020-06-06 10:11:12 -0600
commitfd1b7e50bec5c28a9f6dcef7a147dd79b891c20c (patch)
treee45ee899f31b5d12897391a7065e1c32da8fb26d /dev/utah
parent2c855db95b2f81bcc28a8d6f9c0d622810d76852 (diff)
downloadpig.observer-fd1b7e50bec5c28a9f6dcef7a147dd79b891c20c.tar.gz
pig.observer-fd1b7e50bec5c28a9f6dcef7a147dd79b891c20c.zip
persist coordinates alongside camera info
Diffstat (limited to 'dev/utah')
-rw-r--r--dev/utah/convert.py27
1 files changed, 11 insertions, 16 deletions
diff --git a/dev/utah/convert.py b/dev/utah/convert.py
index cbad592..b02fc5c 100644
--- a/dev/utah/convert.py
+++ b/dev/utah/convert.py
@@ -3,27 +3,22 @@ from collections import defaultdict
import xml.etree.ElementTree as ET
from pprint import pprint
-map_areas = [[29, "Statewide"], [44, "I-15 / I-70 Junction"], [30, "Farmington"], [8, "Ogden"], [9, "Park City"],
- [14, "Provo / Orem"], [43, "Richfield"], [7, "Salt Lake City"], [31, "Sandy"], [27, "St. George"],
- [41, "US-6"], [45, "I-15 Technology Corridor Project"]]
-map_areas = dict(map_areas)
-
-names = dict()
+info = dict()
for place in ET.parse('UtahKML.xml').findall('.//{*}Placemark'):
cam_id = int(place.attrib['id'])
cam_name = place.find(".//{*}SimpleData[@name='DisplayName']").text
- names[cam_id] = cam_name
+ coords = [float(x) for x in place.find(".//{*}coordinates").text.split(',')]
+ info[cam_id] = {'name': cam_name, 'coords': coords}
-sources = defaultdict(list)
+sources = []
with open('cameras.json', 'r') as f:
places = json.load(f)
for place in places:
- area = place['mapAreaId']
- if area in map_areas:
- area = map_areas[area]
- cam_id = place['entityId']
- url = place['url']
- name = names[cam_id]
- sources[area].append({'id': cam_id, 'url': url, 'name': name})
+ cam_id = place['entityId']
+ url = place['url']
+ this_info = info[cam_id]
+ name = this_info['name']
+ coords = this_info['coords']
+ sources.append({'coords': coords, 'cams': [{'id': cam_id, 'url': url, 'name': name}]})
with open('sources.json', 'w') as f:
- json.dump(dict(sources), f)
+ json.dump(sources, f)