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.
45 lines
935 B
Python
45 lines
935 B
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
|
||
|
|
||
|
|
||
|
@dataclass_json
|
||
|
@dataclass
|
||
|
class CoronaCountry:
|
||
|
country_region: str
|
||
|
quelle: str
|
||
|
|
||
|
|
||
|
def sende_daten(url, table, headers, daten):
|
||
|
url = f"{url}{table}"
|
||
|
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)
|
||
|
|
||
|
|
||
|
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")
|
||
|
|
||
|
|