32 lines
660 B
Python
Executable file
32 lines
660 B
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()
|
|
|
|
for c in res.json():
|
|
cameras.append({
|
|
"type": "Feature",
|
|
"geometry": {
|
|
"type": "Point",
|
|
"coordinates": [c['location']['longitude'], c['location']['latitude']], # yes, [lon, lat] since it's [x, y]
|
|
},
|
|
"properties": {
|
|
'originalData': c,
|
|
},
|
|
})
|
|
|
|
geojson = {
|
|
"type": "FeatureCollection",
|
|
"features": cameras,
|
|
}
|
|
|
|
with open("data.geojson", "w") as f:
|
|
f.write(json.dumps(geojson))
|
|
|
|
print(f"{len(cameras)} locations found")
|