2024-01-30 00:37:34 -06:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
|
2024-01-31 01:17:04 -06:00
|
|
|
states = {
|
|
|
|
"Georgia": "https://511ga.org/",
|
|
|
|
"Louisiana": "https://www.511la.org/",
|
|
|
|
"Nevada": "https://www.nvroads.com/",
|
|
|
|
"NewYork": "https://www.511ny.org/",
|
|
|
|
"Wisconsin": "https://511wi.gov/"
|
|
|
|
}
|
2024-01-30 00:37:34 -06:00
|
|
|
|
|
|
|
for state, baseURL in states.items():
|
|
|
|
query={
|
|
|
|
"columns": [ # no clue what any of this is, so here it stays
|
|
|
|
{
|
|
|
|
"data": None,
|
|
|
|
"name": "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "sortId",
|
|
|
|
"s": True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "region",
|
|
|
|
"s": True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "county",
|
|
|
|
"s": True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "roadway",
|
|
|
|
"s": True,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "description1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data": 6,
|
|
|
|
"name": "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
"start": 0,
|
|
|
|
"length": 100,
|
|
|
|
}
|
|
|
|
|
|
|
|
cameras = []
|
|
|
|
available_cameras = 999_999 # lots
|
|
|
|
|
|
|
|
while len(cameras) < available_cameras:
|
|
|
|
res = requests.get(f"{baseURL}/List/GetData/Cameras", {
|
|
|
|
"query": json.dumps(query),
|
|
|
|
"lang": "en",
|
|
|
|
})
|
|
|
|
res.raise_for_status()
|
|
|
|
res = res.json()
|
|
|
|
available_cameras = res['recordsTotal']
|
|
|
|
for c in res['data']:
|
|
|
|
cameras.append({
|
|
|
|
"type": "Feature",
|
|
|
|
"geometry": {
|
|
|
|
"type": "Point",
|
|
|
|
"coordinates": [c['longitude'], c['latitude']], # yes, [lon, lat] since it's [x, y]
|
|
|
|
},
|
|
|
|
"properties": {
|
2024-01-31 01:17:04 -06:00
|
|
|
'name': c['displayName'],
|
|
|
|
'views': [{
|
|
|
|
'hasVideo': c['videoUrl'],
|
|
|
|
'src': c['videoUrl'][0] if isinstance(c['videoUrl'], list) else c['videoUrl'], # LA returns multiple (identical?) streams
|
|
|
|
}],
|
2024-01-30 00:37:34 -06:00
|
|
|
},
|
|
|
|
})
|
|
|
|
query['start'] += 100
|
|
|
|
|
|
|
|
geojson = {
|
|
|
|
"type": "FeatureCollection",
|
|
|
|
"features": cameras,
|
|
|
|
}
|
|
|
|
|
|
|
|
with open(f"data/{state}.geojson", "w") as f:
|
|
|
|
f.write(json.dumps(geojson))
|
|
|
|
|
|
|
|
print(f"{len(cameras)} locations found for {state}")
|
|
|
|
|
|
|
|
# hack hack hack
|
|
|
|
#
|
|
|
|
# If I write this to one big file, I can't take advantage of any lazy loading
|
|
|
|
# for performance reasons, so I'm constrained to having a bunch of files. I
|
|
|
|
# can't programmatically import those, since es6 imports don't allow for that.
|
|
|
|
# So, codegen it is (and fairly gross codegen at that!).
|
|
|
|
with open('data/states.js', 'w') as f:
|
|
|
|
for state in states:
|
|
|
|
f.write(f"import {state} from './{state}.geojson?url';\n")
|
|
|
|
f.write('\nexport default {\n')
|
|
|
|
for state in states:
|
|
|
|
f.write(f" {state}: {state},\n")
|
|
|
|
f.write("};\n")
|