Add debug logging, debug add manual submissions to feed
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import logging
|
import os, logging
|
||||||
|
DEBUG = os.environ.get('DEBUG')
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
level=logging.INFO)
|
level=logging.DEBUG if DEBUG else logging.INFO)
|
||||||
|
|
||||||
import gevent
|
import gevent
|
||||||
from gevent import monkey
|
from gevent import monkey
|
||||||
@@ -61,10 +62,17 @@ def apisearch():
|
|||||||
res.headers['content-type'] = 'application/json'
|
res.headers['content-type'] = 'application/json'
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
@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:
|
try:
|
||||||
url = request.form['url']
|
url = request.form['url']
|
||||||
|
for prefix in ['http://', 'https://']:
|
||||||
|
if url.lower().startswith(prefix):
|
||||||
|
break
|
||||||
|
else: # for
|
||||||
|
url = 'http://' + url
|
||||||
|
|
||||||
nid = new_id()
|
nid = new_id()
|
||||||
|
|
||||||
logging.info('Manual submission: ' + url)
|
logging.info('Manual submission: ' + url)
|
||||||
@@ -89,7 +97,7 @@ def submit():
|
|||||||
ref = url
|
ref = url
|
||||||
|
|
||||||
existing = database.get_story_by_ref(ref)
|
existing = database.get_story_by_ref(ref)
|
||||||
if existing:
|
if existing and not DEBUG:
|
||||||
return {'nid': existing.sid}
|
return {'nid': existing.sid}
|
||||||
else:
|
else:
|
||||||
story = dict(id=nid, ref=ref, source=source)
|
story = dict(id=nid, ref=ref, source=source)
|
||||||
@@ -97,6 +105,11 @@ def submit():
|
|||||||
if valid:
|
if valid:
|
||||||
database.put_story(story)
|
database.put_story(story)
|
||||||
search.put_story(story)
|
search.put_story(story)
|
||||||
|
|
||||||
|
if DEBUG:
|
||||||
|
logging.info('Adding manual ref: {}, id: {}, source: {}'.format(ref, nid, source))
|
||||||
|
database.put_ref(ref, nid, source)
|
||||||
|
|
||||||
return {'nid': nid}
|
return {'nid': nid}
|
||||||
else:
|
else:
|
||||||
raise Exception('Invalid article')
|
raise Exception('Invalid article')
|
||||||
|
|||||||
Reference in New Issue
Block a user