From 7b31fcf690af6e2cd8a4c9d8bc48f498b70dd38e Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 28 Jan 2020 04:20:05 +0000 Subject: [PATCH] Remove keys of uncached stories --- apiserver/server.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apiserver/server.py b/apiserver/server.py index 5c7dfa8..5f18f8e 100644 --- a/apiserver/server.py +++ b/apiserver/server.py @@ -42,11 +42,8 @@ with shelve.open(DATA_FILE) as db: nid = news_ref_to_id[ref] _ = news_cache[nid] except KeyError as e: - logging.error('Unable to find key: ' + str(e)) - logging.info('Clearing caches...') - news_list = [] - news_ref_to_id = {} - news_cache = {} + logging.error('Unable to find key {}. Trying to remove...'.format(str(e))) + news_list.remove(str(e)) def get_story(sid): if sid in news_cache: @@ -73,7 +70,12 @@ cors = CORS(flask_app) @flask_app.route('/api') def api(): - front_page = [news_cache[news_ref_to_id[ref]] for ref in news_list] + try: + front_page = [news_cache[news_ref_to_id[ref]] for ref in news_list] + except KeyError as e: + logging.error('Unable to find key {}. Trying to remove...'.format(str(e))) + news_list.remove(str(e)) + front_page = [copy.copy(x) for x in front_page if 'title' in x and x['title']] front_page = front_page[:60] for story in front_page: