-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
freifunkAPIupdater.py
45 lines (36 loc) · 1.3 KB
/
freifunkAPIupdater.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
#!/usr/bin/env python
import sys
import json
from datetime import datetime
file_path = "cities_to_nodes_urls.json"
# Das Dictionary aus der JSON-Datei laden
with open(file_path, "r") as file:
cities_to_urls = json.load(file)
for city, url in cities_to_urls.items():
#Load API json
filenamecity = f"{city}.json"
with open(filenamecity, encoding="utf8") as json_data:
data = json.load(json_data)
json_data.close()
#Load Results json for Update
filename_result = f"{city}-results.json"
try:
with open(filename_result, encoding="utf8") as json_resultdata:
updatedata = json.load(json_resultdata)
json_resultdata.close()
except OSError as ex:
print(f"Error opening {filename_result}. Skipping.")
continue
nodes = updatedata["online_nodes"]
data["state"]["lastchange"] = datetime.now().astimezone().replace(microsecond=0).isoformat()
data["state"]["nodes"] = int(nodes)
print(city)
print(data["state"]["lastchange"])
print(data["state"]["nodes"])
try:
with open(filenamecity, 'w', encoding="utf8") as fn:
json.dump(data, fn, indent=4, ensure_ascii=False)
fn.close()
except OSError as ex:
print(f"Error saving {filename_result}. Skipping.")
continue