maps.chandlerswift.com/layers/dot-cams/al/get_data.py
Chandler Swift dbcd151364
Refactor DOT cam layers; misc features
* Add more travel-iq states
 * Combine DOT cam layer UI into single place
 * Use standard schema for cam data
 * Differentiate between photo and video cameras
2024-01-31 01:17:04 -06:00

74 lines
2.2 KiB
Python
Executable file

#!/usr/bin/python3
import requests
import json
cameras = []
res = requests.get("https://api.algotraffic.com/v3.0/Cameras")
res.raise_for_status()
# {
# "id": 1164,
# "location": {
# "latitude": 30.56705,
# "longitude": -88.19211,
# "city": "Theodore",
# "county": "Mobile",
# "displayRouteDesignator": "I-10",
# "routeDesignator": "I-10",
# "routeDesignatorType": "Interstate",
# "displayCrossStreet": "Theodore Dawes Rd",
# "crossStreet": "Theodore Dawes Rd",
# "crossStreetType": "Arterial",
# "direction": "East",
# "linearReference": 14.0
# },
# "responsibleRegion": "Southwest",
# "hlsUrl": "https://cdn3.wowza.com/5/aTZuSEJVaHcxakdx/mobile-fastly/mob-cam-c090.stream/playlist.m3u8",
# "imageUrl": "https://api.algotraffic.com/v3/Cameras/1164/snapshot.jpg",
# "accessLevel": "Public"
# }
for c in res.json():
try:
if c['accessLevel'] != 'Public':
print("warn: access level is not public; ignoring:", c)
continue
if not c['hlsUrl'].startswith('https://'):
raise Exception("invalid hlsUrl")
if not c['imageUrl'].startswith('https://'):
raise Exception("invalid imageUrl")
cameras.append({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [c['location']['longitude'], c['location']['latitude']], # yes, [lon, lat] since it's [x, y]
},
"properties": {
"name": c['location']['displayRouteDesignator'] + '/' + c['location']['displayCrossStreet'],
"views": [
{
'hasVideo': True,
'src': c['hlsUrl'],
},
# {
# 'hasVideo': False,
# 'src': c['imageUrl'],
# }
]
},
})
except Exception as e:
print(c)
raise e
geojson = {
"type": "FeatureCollection",
"features": cameras,
}
with open("data.geojson", "w") as f:
f.write(json.dumps(geojson))
print(f"{len(cameras)} locations found")