-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
50 lines (36 loc) · 1.29 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env python3
# not yet used
# Copyright (c) 2016, Jan Brohl <janbrohl@t-online.de>
# All rights reserved.
import bottle
import interfaces.ckan
import interfaces.netkan
import datetime
from json import loads
from ckan_util import split_version
ckan = interfaces.ckan.full()
netkan = interfaces.netkan.active_full()
updated = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M")
ckan.sort(key=(lambda e: (e["identifier"], split_version(e["version"]))))
netkan.sort(key=(lambda e: e["identifier"]))
app = bottle.Bottle()
@app.get("/ckan/")
def ckan_json():
known_raw = bottle.request.query.known
if known_raw:
where_eq = tuple(loads(known_raw).items())
return {"data": [e for e in ckan if all(v == e.get(k, None) for k, v in where_eq)], "updated": updated}
return {"data": ckan, "updated": updated}
@app.get("/netkan/")
def netkan_json():
known_raw = bottle.request.query.known
if known_raw:
where_eq = tuple(loads(known_raw).items())
return {"data": [e for e in netkan if all(v == e.get(k, None) for k, v in where_eq)], "updated": updated}
return {"data": netkan, "updated": updated}
@app.get("/")
@app.get("/<path:path>")
def static(path="index.html"):
return bottle.static_file(path, "static")
if __name__ == "__main__":
app.run()