-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
executable file
·94 lines (73 loc) · 3.07 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
import time
import requests
import os
def saveurl(url, filename, expectedContentType):
print("Downloading ", url)
r = requests.get(url, allow_redirects=True)
r.raise_for_status()
actualContentType = r.headers['Content-Type']
if actualContentType == expectedContentType:
open(filename, 'wb').write(r.content)
print("Saved", filename)
else:
raise Exception("Unexpected content-type:", actualContentType)
overpass_api_url = "https://overpass-api.de/api/interpreter"
overpass_query_aed_json = """
[out:json]
[timeout:300];
area(id:3600218657)->.slovenia;
(
nwr[emergency=defibrillator](area.slovenia);
);
out center body qt;
"""
#https://overpass-turbo.eu/s/1eNQ
overpass_query_aed_csv = """
[out:csv(
::"id", ::type, ::lat, ::lon, name,
phone, "emergency:phone", image, website, description, operator,
opening_hours, indoor, access, wheelchair,
"defibrillator:location", "defibrillator:location:en", "defibrillator:location:sl", "defibrillator:location:it", "defibrillator:location:hu", "defibrillator:location:de";
true; ","
)]
[timeout:300];
area(id:3600218657)->.slovenia;
(
nwr[emergency=defibrillator](area.slovenia);
);
out center body qt;
"""
def saveFromOverpassAPI(
query: str,
filename: str,
expectedContentType: str,
api_url: str = overpass_api_url,
):
print(f"Requesting data from Overpass API. [url={api_url}]")
response = requests.post(url=api_url, data={"data": query})
response.raise_for_status()
print("Downloaded data from Overpass API.")
actualContentType = response.headers['Content-Type']
if actualContentType == expectedContentType:
if filename != None:
open(filename, 'wb').write(response.content)
print("Saved", filename)
else:
raise Exception("Unexpected content-type:", actualContentType)
def import_openstreetmap():
if not os.path.exists("sources/openstreetmap.org"):
os.makedirs("sources/openstreetmap.org")
# saveFromOverpassAPI(overpass_query_aed_json, "sources/openstreetmap.org/openstreetmap.json", "application/json")
saveFromOverpassAPI(overpass_query_aed_csv, "sources/openstreetmap.org/slovenia.csv", "text/csv")
def import_opsi():
# https://podatki.gov.si/data/search?s=defibrilatorjev
# https://podatki.gov.si/dataset/lokacije-defibrilatorjev-aed
saveurl("https://podatki.gov.si/dataset/5abdc896-d7b3-43a1-b580-ab2e6cff981c/resource/945e24c6-4808-4ee7-a86c-ff56a703fc6a/download/lokacijeaedvobinibreice.csv", "sources/podatki.gov.si/brezice.csv", "text/csv")
# https://podatki.gov.si/dataset/evidenca-defibrilatorjev-v-obcini-braslovce
saveurl("https://podatki.gov.si/dataset/789a9868-a24c-4fce-9275-28d2a7b4415f/resource/e90a1326-a98f-4169-9665-e6abab99cf25/download/evidencadefibrilatorjevobinibraslove.xlsx", "sources/podatki.gov.si/braslovce.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
# TODO: add others
if __name__ == "__main__":
update_time = int(time.time())
import_openstreetmap()
import_opsi()