Skip to content

Instantly share code, notes, and snippets.

@predic8
Created March 30, 2020 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save predic8/8c81ed152f4ae75c6eeaa76a49844eec to your computer and use it in GitHub Desktop.
Save predic8/8c81ed152f4ae75c6eeaa76a49844eec to your computer and use it in GitHub Desktop.
Covid API mit Datum
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