Begin stats API route
This commit is contained in:
@@ -30,6 +30,8 @@ database.init()
|
|||||||
search.init()
|
search.init()
|
||||||
|
|
||||||
news_index = 0
|
news_index = 0
|
||||||
|
ref_list = []
|
||||||
|
current_item = {}
|
||||||
|
|
||||||
def new_id():
|
def new_id():
|
||||||
nid = gen_rand_id()
|
nid = gen_rand_id()
|
||||||
@@ -51,6 +53,18 @@ def api():
|
|||||||
res.headers['content-type'] = 'application/json'
|
res.headers['content-type'] = 'application/json'
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@flask_app.route('/api/stats', strict_slashes=False)
|
||||||
|
def apistats():
|
||||||
|
stats = {
|
||||||
|
'news_index': news_index,
|
||||||
|
'ref_list': ref_list,
|
||||||
|
'len_ref_list': len(ref_list),
|
||||||
|
'current_item': current_item,
|
||||||
|
}
|
||||||
|
|
||||||
|
return stats
|
||||||
|
|
||||||
|
|
||||||
@flask_app.route('/api/search', strict_slashes=False)
|
@flask_app.route('/api/search', strict_slashes=False)
|
||||||
def apisearch():
|
def apisearch():
|
||||||
q = request.args.get('q', '')
|
q = request.args.get('q', '')
|
||||||
@@ -173,7 +187,7 @@ def static_story(sid):
|
|||||||
http_server = WSGIServer(('', 33842), flask_app)
|
http_server = WSGIServer(('', 33842), flask_app)
|
||||||
|
|
||||||
def feed_thread():
|
def feed_thread():
|
||||||
global news_index
|
global news_index, ref_list, current_item
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
@@ -194,13 +208,13 @@ def feed_thread():
|
|||||||
|
|
||||||
# update current stories
|
# update current stories
|
||||||
if news_index < len(ref_list):
|
if news_index < len(ref_list):
|
||||||
item = ref_list[news_index]
|
current_item = ref_list[news_index]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
story_json = database.get_story(item['sid']).full_json
|
story_json = database.get_story(current_item['sid']).full_json
|
||||||
story = json.loads(story_json)
|
story = json.loads(story_json)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
story = dict(id=item['sid'], ref=item['ref'], source=item['source'])
|
story = dict(id=current_item['sid'], ref=current_item['ref'], source=current_item['source'])
|
||||||
|
|
||||||
logging.info('Updating {} story: {}, index: {}'.format(story['source'], story['ref'], news_index))
|
logging.info('Updating {} story: {}, index: {}'.format(story['source'], story['ref'], news_index))
|
||||||
|
|
||||||
@@ -209,8 +223,8 @@ def feed_thread():
|
|||||||
database.put_story(story)
|
database.put_story(story)
|
||||||
search.put_story(story)
|
search.put_story(story)
|
||||||
else:
|
else:
|
||||||
database.del_ref(item['ref'])
|
database.del_ref(current_item['ref'])
|
||||||
logging.info('Removed ref {}'.format(item['ref']))
|
logging.info('Removed ref {}'.format(current_item['ref']))
|
||||||
else:
|
else:
|
||||||
logging.info('Skipping index: ' + str(news_index))
|
logging.info('Skipping index: ' + str(news_index))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user