-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwd_warnings.py
executable file
·41 lines (32 loc) · 941 Bytes
/
dwd_warnings.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
#!/usr/bin/env python3
# ---------------------------------------------------------------------------
# Aktuelle DWD-Warnungen ermitteln
#
# Mario Zimmermann <[email protected]>
# 2024-06-03
# ---------------------------------------------------------------------------
from configparser import ConfigParser
import requests
import json
import re
import time
# ConfigFile lesen
config_object = ConfigParser()
config_object.read("mower_weather.ini")
DWD = config_object["DWD"]
try_count = 0
success = False
while not success and try_count < 10:
response = requests.get(DWD["url"])
text = response.text
text = re.sub("warnWetter.loadWarnings\(", "", text)
text = re.sub("\);", "", text)
try:
data = json.loads(text)
success = True
except json.decoder.JSONDecodeError as e:
try_count += 1
time.sleep(1)
if not success:
exit()
print(json.dumps(data, indent=2, ensure_ascii=False))