add related stories (in api only)
This commit is contained in:
parent
4ec50e20cb
commit
5efc6ef2d3
|
@ -1,6 +1,4 @@
|
|||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from sqlalchemy import create_engine, Column, String, ForeignKey, Integer
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
@ -67,6 +65,13 @@ def get_story_by_ref(ref):
|
|||
session = Session()
|
||||
return session.query(Story).filter(Story.ref==ref).first()
|
||||
|
||||
def get_stories_by_url(url):
|
||||
session = Session()
|
||||
return session.query(Story).\
|
||||
filter(Story.title != None).\
|
||||
filter(Story.meta['url'].as_string() == url).\
|
||||
order_by(Story.meta['date'].desc())
|
||||
|
||||
def get_reflist():
|
||||
session = Session()
|
||||
q = session.query(Reflist).order_by(Reflist.rid.desc())
|
||||
|
|
|
@ -163,6 +163,8 @@ def get_sitemap_date(a):
|
|||
return a.find('lastmod').text
|
||||
if a.find('news:publication_date'):
|
||||
return a.find('news:publication_date').text
|
||||
if a.find('ns2:publication_date'):
|
||||
return a.find('ns2:publication_date').text
|
||||
return ''
|
||||
|
||||
class Sitemap(_Base):
|
||||
|
|
|
@ -99,7 +99,9 @@ def submit():
|
|||
def story(sid):
|
||||
story = database.get_story(sid)
|
||||
if story:
|
||||
res = Response(json.dumps({"story": story.data}))
|
||||
related = database.get_stories_by_url(story.meta['url'])
|
||||
related = [r.meta for r in related]
|
||||
res = Response(json.dumps({"story": story.data, "related": related}))
|
||||
res.headers['content-type'] = 'application/json'
|
||||
return res
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user