From 2e2c9ae83750a38c223a96add8b8d4b9b8da13f2 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 4 Jul 2022 06:05:33 +0000 Subject: [PATCH] Move FEED_LENGTH to settings.py, use for search results --- apiserver/search.py | 2 +- apiserver/server.py | 8 ++++---- apiserver/settings.py.example | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apiserver/search.py b/apiserver/search.py index 9161179..24f5a7a 100644 --- a/apiserver/search.py +++ b/apiserver/search.py @@ -53,7 +53,7 @@ def put_story(story): def search(q): if not SEARCH_ENABLED: return [] - params = dict(q=q, limit=100) + params = dict(q=q, limit=settings.FEED_LENGTH) r = meili_api(requests.get, 'indexes/qotnews/search', params=params, parse_json=False) return r diff --git a/apiserver/server.py b/apiserver/server.py index d567229..edb32d8 100644 --- a/apiserver/server.py +++ b/apiserver/server.py @@ -15,6 +15,7 @@ import traceback import time from urllib.parse import urlparse, parse_qs +import settings import database import search import feed @@ -27,7 +28,6 @@ from flask_cors import CORS database.init() search.init() -FEED_LENGTH = 75 news_index = 0 def new_id(): @@ -43,7 +43,7 @@ cors = CORS(flask_app) @flask_app.route('/api') def api(): skip = request.args.get('skip', 0) - limit = request.args.get('limit', FEED_LENGTH) + limit = request.args.get('limit', settings.FEED_LENGTH) stories = database.get_stories(limit, skip) # hacky nested json res = Response('{"stories":[' + ','.join(stories) + ']}') @@ -177,7 +177,7 @@ def feed_thread(): logging.info('Already have ID / ref, skipping.') continue - ref_list = database.get_reflist(FEED_LENGTH) + ref_list = database.get_reflist(settings.FEED_LENGTH) # update current stories if news_index < len(ref_list): @@ -204,7 +204,7 @@ def feed_thread(): gevent.sleep(6) news_index += 1 - if news_index == FEED_LENGTH: news_index = 0 + if news_index == settings.FEED_LENGTH: news_index = 0 except KeyboardInterrupt: logging.info('Ending feed thread...') diff --git a/apiserver/settings.py.example b/apiserver/settings.py.example index 391d751..a039b24 100644 --- a/apiserver/settings.py.example +++ b/apiserver/settings.py.example @@ -4,6 +4,7 @@ # Feed Lengths # Number of top items from each site to pull # set to 0 to disable that site +FEED_LENGTH = 75 NUM_HACKERNEWS = 15 NUM_LOBSTERS = 10 NUM_REDDIT = 15