forked from tanner/qotnews
add update-story.py
This commit is contained in:
parent
f5e65632b8
commit
32bc3b906b
|
@ -73,6 +73,13 @@ def get_stories_by_url(url):
|
|||
filter(Story.meta['url'].as_string() == url).\
|
||||
order_by(Story.meta['date'].desc())
|
||||
|
||||
def get_ref_by_sid(sid):
|
||||
session = Session()
|
||||
x = session.query(Reflist).\
|
||||
filter(Reflist.sid == sid).\
|
||||
first()
|
||||
return dict(ref=x.ref, sid=x.sid, source=x.source, urlref=x.urlref)
|
||||
|
||||
def get_reflist():
|
||||
session = Session()
|
||||
q = session.query(Reflist).order_by(Reflist.rid.desc())
|
||||
|
|
45
apiserver/update-story.py
Normal file
45
apiserver/update-story.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import logging
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
|
||||
import database
|
||||
import feed
|
||||
import search
|
||||
|
||||
database.init()
|
||||
search.init()
|
||||
|
||||
def _update_current_story(story, item):
|
||||
logging.info('Updating story: {}'.format(str(story['ref'])))
|
||||
|
||||
valid = feed.update_story(story, urlref=item['urlref'])
|
||||
if valid:
|
||||
database.put_story(story)
|
||||
search.put_story(story)
|
||||
else:
|
||||
database.del_ref(item['ref'])
|
||||
logging.info('Removed ref {}'.format(item['ref']))
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 2:
|
||||
sid = sys.argv[1]
|
||||
else:
|
||||
print('Usage: python delete-story.py [story id]')
|
||||
exit(1)
|
||||
|
||||
item = database.get_ref_by_sid(sid)
|
||||
|
||||
if item:
|
||||
story = database.get_story(item['sid']).data
|
||||
if story:
|
||||
print('Updating story:')
|
||||
_update_current_story(story, item)
|
||||
else:
|
||||
print('Story not found. Exiting.')
|
||||
else:
|
||||
print('Story not found. Exiting.')
|
Loading…
Reference in New Issue
Block a user