mirror of
https://github.com/heyarne/berliner-winter.git
synced 2026-05-06 19:23:39 +02:00
Add API for location
This commit is contained in:
parent
c09a1d78a2
commit
13791c0599
2 changed files with 25 additions and 0 deletions
10
models.py
10
models.py
|
|
@ -1,3 +1,4 @@
|
||||||
|
import json
|
||||||
from peewee import *
|
from peewee import *
|
||||||
|
|
||||||
db = SqliteDatabase('violence.db')
|
db = SqliteDatabase('violence.db')
|
||||||
|
|
@ -6,6 +7,15 @@ class BaseModel(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
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):
|
class Article(BaseModel):
|
||||||
"""
|
"""
|
||||||
An article is a single incident as crawled from the reach-out webpage
|
An article is a single incident as crawled from the reach-out webpage
|
||||||
|
|
|
||||||
15
server.py
Normal file
15
server.py
Normal 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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue