aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'bh20simplewebuploader/main.py')
-rw-r--r--bh20simplewebuploader/main.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index d6e5249..de3ba3f 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -248,28 +248,36 @@ def load_schema_generate_form():
FORM_ITEMS = load_schema_generate_form()
-@app.route('/')
-def send_home():
- """
- Send the front page.
- """
+
+def get_feed_items(name, start=0, stop=9):
redis_client = redis.Redis(host=os.environ.get('HOST', 'localhost'),
port=os.environ.get('PORT', 6379),
- db=os.environ.get('REDIS_DB', 0))
- tweets = []
+ db=os.environ.get('REDIS_DB', 0))
+ feed_items = []
try:
- for tweet_id in redis_client.zrevrange('bh20-tweet-score:',
- 0, -1):
- tweets.append(
- {k.decode("utf-8"): v.decode("utf-8") for k, v in
- redis_client.hgetall(tweet_id).items()}
- )
+ for el in redis_client.zrevrange(name, start, stop):
+ feed_dict = redis_client.hgetall(el)
+ if feed_dict and int(feed_dict.get(b"score", "0")) > 0:
+ feed_items.append(
+ {k.decode("utf-8"): v.decode("utf-8") for k, v in
+ feed_dict.items()})
+ return feed_items
except redis.exceptions.ConnectionError as e:
logging.warning(f"redis connect failed {e}")
pass
- return render_template('home.html', menu='HOME',
- tweets=tweets,
- load_map=True)
+
+
+@app.route('/')
+def send_home():
+ """
+ Send the front page.
+ """
+ return render_template(
+ 'home.html', menu='HOME',
+ tweets=get_feed_items("bh20-tweet-score:"),
+ commits=get_feed_items("bh20-commit-score:"),
+ pubmed_articles=get_feed_items("bh20-pubmed-score:"),
+ load_map=True)
@app.route('/upload')