You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Corona/db_model_postgrest.py

56 lines
1.3 KiB
Python

5 years ago
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
5 years ago
@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
5 years ago
def sende_daten(url, table, headers, daten):
url = f"{url}{table}"
4 years ago
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:
5 years ago
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")