Add debug logging, debug add manual submissions to feed

This commit is contained in:
2025-11-20 21:55:45 +00:00
parent 845d87ec55
commit e867d5d868

View File

@@ -1,7 +1,8 @@
import logging
import os, logging
DEBUG = os.environ.get('DEBUG')
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
level=logging.DEBUG if DEBUG else logging.INFO)
import gevent
from gevent import monkey
@@ -61,10 +62,17 @@ def apisearch():
res.headers['content-type'] = 'application/json'
return res
@flask_app.route('/api/submit', methods=['POST'], strict_slashes=False)
def submit():
try:
url = request.form['url']
for prefix in ['http://', 'https://']:
if url.lower().startswith(prefix):
break
else: # for
url = 'http://' + url
nid = new_id()
logging.info('Manual submission: ' + url)
@@ -89,7 +97,7 @@ def submit():
ref = url
existing = database.get_story_by_ref(ref)
if existing:
if existing and not DEBUG:
return {'nid': existing.sid}
else:
story = dict(id=nid, ref=ref, source=source)
@@ -97,6 +105,11 @@ def submit():
if valid:
database.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}
else:
raise Exception('Invalid article')