From fbafe714f4068a8bf14d95454fae166422633438 Mon Sep 17 00:00:00 2001 From: Hofei90 <29521028+Hofei90@users.noreply.github.com> Date: Mon, 9 Nov 2020 20:15:27 +0100 Subject: [PATCH] add Intensivregister Deutschland --- db_model.py | 15 ++++++++++++++- db_model_postgrest.py | 12 ++++++++++++ scrape_corona.py | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/db_model.py b/db_model.py index c7f588d..cb9f016 100644 --- a/db_model.py +++ b/db_model.py @@ -38,8 +38,21 @@ class CoronaStatistik(BaseModel): wert = FloatField() +class Intensivregister(BaseModel): + ts = DateTimeField() + bundesland = TextField() + covid_aktuell = IntegerField() + covid_aktuell_beatmet = IntegerField() + intensivbetten_belegt = IntegerField() + intensivbetten_frei = IntegerField() + intensivbetten_notfall = IntegerField() + + class Meta: + primary_key = CompositeKey('ts', 'bundesland') + + def create_tables(): - database.create_tables([CoronaDaten, CoronaStatistik]) + database.create_tables([CoronaDaten, CoronaStatistik, Intensivregister]) diff --git a/db_model_postgrest.py b/db_model_postgrest.py index 5c4a210..0433df6 100644 --- a/db_model_postgrest.py +++ b/db_model_postgrest.py @@ -18,6 +18,18 @@ class CoronaDaten: 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: diff --git a/scrape_corona.py b/scrape_corona.py index 5b6f9c9..b1dd133 100644 --- a/scrape_corona.py +++ b/scrape_corona.py @@ -35,7 +35,14 @@ QUELLEN = { "%A4ndern/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel" "=esriSpatialRelIntersects&outFields=*&orderByFields=faelle_100000_EW%20desc&resultOffset=0" "&resultRecordCount=50&cacheHint=true", - "rki_landkreis": "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=cases%20desc&resultOffset=0&resultRecordCount=1000&cacheHint=true" + "rki_landkreis": "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten" + "/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel" + "=esriSpatialRelIntersects&outFields=*&orderByFields=cases%20desc&resultOffset=0" + "&resultRecordCount=1000&cacheHint=true " +} + +INTENSIVREGISTER = { + "intensivregister": "https://www.intensivregister.de/api/public/reporting/laendertabelle" } @@ -55,6 +62,12 @@ def daten_abrufen(url): return json_text["features"] +def intensivbetten_daten_abrufen(url): + response = requests.get(url) + json_text = json.loads(response.text) + return json_text["data"] + + def jhu_daten_erstellen(quelle, daten): daten_dict = {} for data in daten: @@ -116,6 +129,21 @@ def rki_landkreis_daten_erstellen(quelle, daten): return daten_dict +def intensivbetten_daten_erstellen(daten): + daten_dict = {} + for data in daten: + daten_dict[data['bundesland']] = (db.Intensivregister( + datetime.datetime.strptime(data['creationTimestamp'], "%Y-%m-%dT%H:%M:%SZ"), + data['bundesland'], + data['faelleCovidAktuell'], + data['faelleCovidAktuellBeatmet'], + data['intensivBettenBelegt'], + data['intensivBettenFrei'], + data['intensivBettenNotfall7d'] + )) + return daten_dict + + def daten_erstellen(quelle, daten): if quelle == "jhu": daten_db = jhu_daten_erstellen(quelle, daten) @@ -144,12 +172,20 @@ def headers_erstellen(): def main(): headers = headers_erstellen() + # Coronazahlen for quelle, url in QUELLEN.items(): json_daten = daten_abrufen(url) daten = daten_erstellen(quelle, json_daten) daten_server = daten_trennen(daten) db.sende_daten(CONFIG["url"], CONFIG["tablename_daten"], headers, daten_server) + # Intensivbetten + for quelle, url in INTENSIVREGISTER.items(): + json_daten = intensivbetten_daten_abrufen(url) + daten = intensivbetten_daten_erstellen(json_daten) + daten_server = daten_trennen(daten) + db.sende_daten((CONFIG["url"]), "intensivregister", headers, daten_server) + if __name__ == "__main__": main()