forked from tanner/qotnews
Add optional skip and limit to API route
This commit is contained in:
parent
3ff917e806
commit
6f64401785
|
@ -68,12 +68,13 @@ def get_reflist(amount):
|
|||
q = session.query(Reflist).order_by(Reflist.rid.desc()).limit(amount)
|
||||
return [dict(ref=x.ref, sid=x.sid, source=x.source) for x in q.all()]
|
||||
|
||||
def get_stories(amount):
|
||||
def get_stories(amount, skip=0):
|
||||
session = Session()
|
||||
q = session.query(Reflist, Story.meta_json).\
|
||||
order_by(Reflist.rid.desc()).\
|
||||
join(Story).\
|
||||
filter(Story.title != None).\
|
||||
offset(skip).\
|
||||
limit(amount)
|
||||
return [x[1] for x in q]
|
||||
|
||||
|
|
|
@ -42,7 +42,9 @@ cors = CORS(flask_app)
|
|||
|
||||
@flask_app.route('/api')
|
||||
def api():
|
||||
stories = database.get_stories(FEED_LENGTH)
|
||||
skip = request.args.get('skip', 0)
|
||||
limit = request.args.get('limit', FEED_LENGTH)
|
||||
stories = database.get_stories(limit, skip)
|
||||
# hacky nested json
|
||||
res = Response('{"stories":[' + ','.join(stories) + ']}')
|
||||
res.headers['content-type'] = 'application/json'
|
||||
|
|
Loading…
Reference in New Issue
Block a user