/stats implemented !

This commit is contained in:
cquest 2016-04-14 17:46:30 +02:00
parent db1e1c8131
commit 183664f1fb

32
backend.py Normal file
View file

@ -0,0 +1,32 @@
# backend.py
# openeventdatabase
import falcon
import psycopg2
import uuid
class StatsResource(object):
def on_get(self, req, resp):
db = psycopg2.connect("dbname=oedb")
cur = db.cursor()
cur.execute("SELECT count(*) from events;")
stat = cur.fetchone()
count_events = stat[0]
cur.close()
db.close()
resp.body = """{"events_count":%s}""" % (count_events)
resp.set_header('X-Powered-By', 'OpenEventDatabase')
resp.set_header('Access-Control-Allow-Origin', '*')
resp.set_header('Access-Control-Allow-Headers', 'X-Requested-With')
resp.status = falcon.HTTP_200
# falcon.API instances are callable WSGI apps
app = falcon.API()
# Resources are represented by long-lived class instances
stats = StatsResource()
# things will handle all requests to the matching URL path
app.add_route('/stats', stats)