mirror of
https://github.com/heyarne/berliner-winter.git
synced 2026-05-06 19:23:39 +02:00
Massage the API response to look like what we want
This commit is contained in:
parent
856cb0550a
commit
7a961b9fc5
1 changed files with 16 additions and 12 deletions
28
server.py
28
server.py
|
|
@ -49,22 +49,26 @@ def articles():
|
||||||
JOIN category ON article.id = category.article_id
|
JOIN category ON article.id = category.article_id
|
||||||
""")
|
""")
|
||||||
|
|
||||||
articles = []
|
articles = {}
|
||||||
for article in c.fetchall():
|
for article in c.fetchall():
|
||||||
article_id = article[0]
|
article_id = article[0]
|
||||||
if locations.get(article_id):
|
if locations.get(article_id):
|
||||||
articles.append({
|
if articles.get(article_id):
|
||||||
"id": article_id,
|
articles[article_id]["categories"].append(article[4])
|
||||||
"date": article[1],
|
else:
|
||||||
"place": article[2],
|
articles[article_id] = {
|
||||||
"description": article[3],
|
"id": article_id,
|
||||||
"category": article[4],
|
"date": article[1],
|
||||||
"lat": locations[article_id][0],
|
"place": article[2],
|
||||||
"lng": locations[article_id][1],
|
"description": article[3],
|
||||||
"place": locations[article_id][2]
|
"categories": [article[4]],
|
||||||
})
|
"lat": locations[article_id][0],
|
||||||
|
"lng": locations[article_id][1],
|
||||||
|
"place": locations[article_id][2]
|
||||||
|
}
|
||||||
conn.close()
|
conn.close()
|
||||||
return json.dumps(articles)
|
|
||||||
|
return json.dumps([article for article_id, article in articles.items()])
|
||||||
|
|
||||||
@bottle.get('/static/<filepath:path>')
|
@bottle.get('/static/<filepath:path>')
|
||||||
def server_static(filepath):
|
def server_static(filepath):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue