Created
March 30, 2020 20:15
-
-
Save predic8/8c81ed152f4ae75c6eeaa76a49844eec to your computer and use it in GitHub Desktop.
Covid API mit Datum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import falcon | |
from json import load, dumps | |
import datetime | |
with open('db.json') as f: | |
db = load(f)["records"] | |
def trans(r): | |
return { | |
"Land": r["geoId"], | |
"Datum": r["dateRep"], | |
"Fälle": r["cases"], | |
} | |
db = list(map( trans,db)) | |
def alle(f): | |
return lambda y: all([ x(y) for x in f]) | |
class CovidApi: | |
def on_get(self, req, resp): | |
datum = req.params.get("datum", None) | |
land = req.params.get("land", None) | |
filters = [] | |
if land: | |
filters.append(lambda r: r["Land"] == land) | |
if datum: | |
filters.append(lambda r: r["Datum"] == datum) | |
resp.media = { | |
"date": str(datetime.datetime.now()) , | |
"data": list(filter( alle(filters), db)) | |
} | |
api = falcon.API() | |
api.add_route('/covid/', CovidApi()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment