maps.chandlerswift.com/layers/dot-cams/al/get_data.py

74 lines
2.2 KiB
Python
Raw Normal View History

2024-01-30 00:22:08 -06:00
#!/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"
# }
2024-01-30 00:22:08 -06:00
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
2024-01-30 00:22:08 -06:00
geojson = {
"type": "FeatureCollection",
"features": cameras,
}
with open("data.geojson", "w") as f:
f.write(json.dumps(geojson))
print(f"{len(cameras)} locations found")