|
|
|
from dataclasses import dataclass
|
|
|
|
from dataclasses_json import dataclass_json
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass_json
|
|
|
|
@dataclass
|
|
|
|
class CoronaDaten:
|
|
|
|
ts: datetime.datetime or str
|
|
|
|
country_region: str
|
|
|
|
quelle: str
|
|
|
|
confirmed: int
|
|
|
|
deaths: int
|
|
|
|
recoverd: int
|
|
|
|
active: int
|
|
|
|
cases7_per_100k: float
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass_json
|
|
|
|
@dataclass
|
|
|
|
class Intensivregister:
|
|
|
|
ts: datetime.datetime or str
|
|
|
|
bundesland: str
|
|
|
|
covid_aktuell: int
|
|
|
|
covid_aktuell_beatmet: int
|
|
|
|
intensivbetten_belegt: int
|
|
|
|
intensivbetten_frei: int
|
|
|
|
intensivbetten_notfall: int
|
|
|
|
|
|
|
|
|
|
|
|
def sende_daten(url, table, headers, daten):
|
|
|
|
url = f"{url}{table}"
|
|
|
|
try:
|
|
|
|
r = requests.post(url, headers=headers, json=[data.to_dict() for data in daten])
|
|
|
|
except AttributeError:
|
|
|
|
for data in daten:
|
|
|
|
try:
|
|
|
|
r = requests.post(url, headers=headers, json=data.to_dict())
|
|
|
|
except AttributeError:
|
|
|
|
r = requests.post(url, headers=headers, data=data)
|
|
|
|
status_auswerten(r, daten)
|
|
|
|
else:
|
|
|
|
status_auswerten(r, daten)
|
|
|
|
|
|
|
|
|
|
|
|
def status_auswerten(r, daten):
|
|
|
|
if not (r.status_code == 200 or r.status_code == 201):
|
|
|
|
print(f"Statuscode: {r.status_code}\n Message: {r.text}")
|
|
|
|
print(daten)
|
|
|
|
else:
|
|
|
|
print("Erfolgreich übertragen")
|
|
|
|
|
|
|
|
|