Grab comments on manually submitted links

This commit is contained in:
Tanner Collin 2019-12-02 23:15:51 +00:00
parent ebcbf1b624
commit 2d80b19414
3 changed files with 36 additions and 13 deletions

View File

@ -89,7 +89,7 @@ def get_first_image(text):
except: except:
return '' return ''
def update_story(story): def update_story(story, manual=False):
res = {} res = {}
logging.info('Updating story ' + str(story['ref'])) logging.info('Updating story ' + str(story['ref']))
@ -109,7 +109,7 @@ def update_story(story):
logging.info('Article not ready yet') logging.info('Article not ready yet')
return False return False
if story['date'] and story['date'] + TWO_DAYS < time.time(): if story['date'] and not manual and story['date'] + TWO_DAYS < time.time():
logging.info('Article too old, removing') logging.info('Article too old, removing')
return False return False

View File

@ -7,7 +7,7 @@ import copy
import threading import threading
import time import time
import shelve import shelve
from urllib.parse import urlparse from urllib.parse import urlparse, parse_qs
import archive import archive
import feed import feed
@ -93,18 +93,39 @@ def search():
@flask_app.route('/api/submit', methods=['POST'], strict_slashes=False) @flask_app.route('/api/submit', methods=['POST'], strict_slashes=False)
def submit(): def submit():
try:
url = request.form['url'] url = request.form['url']
nid = new_id() nid = new_id()
news_story = dict(id=nid, ref=url, source='manual')
parse = urlparse(url)
if 'news.ycombinator.com' in parse.hostname:
source = 'hackernews'
ref = parse_qs(parse.query)['id'][0]
elif 'tildes.net' in parse.hostname and '~' in url:
source = 'tildes'
ref = parse.path.split('/')[2]
elif 'reddit.com' in parse.hostname and 'comments' in url:
source = 'reddit'
ref = parse.path.split('/')[4]
else:
source = 'manual'
ref = url
news_story = dict(id=nid, ref=ref, source=source)
news_cache[nid] = news_story news_cache[nid] = news_story
valid = feed.update_story(news_story) valid = feed.update_story(news_story, manual=True)
if valid: if valid:
archive.update(news_story) archive.update(news_story)
return {'nid': nid} return {'nid': nid}
else: else:
news_cache.pop(nid, '') news_cache.pop(nid, '')
raise Exception('Invalid article')
except BaseException as e:
logging.error('Problem with article submission: {} - {}'.format(e.__class__.__name__, str(e)))
abort(400) abort(400)
@flask_app.route('/api/<sid>') @flask_app.route('/api/<sid>')
def story(sid): def story(sid):
story = get_story(sid) story = get_story(sid)

View File

@ -39,6 +39,8 @@ ALLOWED_TAGS = [
'sub', 'sub',
'details', 'details',
'summary', 'summary',
'br',
'pre',
] ]
clean = Cleaner(tags=ALLOWED_TAGS).clean clean = Cleaner(tags=ALLOWED_TAGS).clean