Add API for location

This commit is contained in:
Arne Schlüter 2015-02-07 17:19:22 +01:00
commit 13791c0599
2 changed files with 25 additions and 0 deletions

View file

@ -1,3 +1,4 @@
import json
from peewee import *
db = SqliteDatabase('violence.db')
@ -6,6 +7,15 @@ class BaseModel(Model):
class Meta:
database = db
def __str__(self):
r = {}
for k in self._data.keys():
try:
r[k] = str(getattr(self, k))
except:
r[k] = json.dumps(getattr(self, k))
return str(r)
class Article(BaseModel):
"""
An article is a single incident as crawled from the reach-out webpage

15
server.py Normal file
View file

@ -0,0 +1,15 @@
import bottle
from json import dumps
from models import *
@bottle.get('/locations/<article_id:int>')
def location(article_id):
return (Location
.select()
.where(Location.article == article_id)
.order_by(Location.confidence.desc(), Location.id.asc())
.dicts()
.get())
if __name__ == '__main__':
bottle.run(host='localhost', port=12345, reloader=True, debug=True)