From 2e2e2280f59b783759b7b70d410fb7a5c59206d5 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 10 Nov 2020 03:42:12 +0300 Subject: Add tweet feed * bh20simplewebuploader/main.py (send_home): Fetch tweets from Redis. * bh20simplewebuploader/static/main.css: Add styles for tweets * bh20simplewebuploader/templates/home.html: Add tweet section in frontpage. --- bh20simplewebuploader/main.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 73503b4..d3b9591 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -7,6 +7,7 @@ import logging import os import sys import re +import redis import string import ruamel.yaml as yaml import pkg_resources @@ -252,8 +253,19 @@ def send_home(): """ Send the front page. """ - - return render_template('home.html', menu='HOME', load_map=True) + redis_client = redis.Redis(host=os.environ.get('HOST', 'localhost'), + port=os.environ.get('PORT', 6379), + db=os.environ.get('REDIS_DB', 0)) + tweets = [] + for tweet_id in redis_client.zrevrange('gn2-tweet-score:', + 0, -1): + tweets.append( + {k.decode("utf-8"): v.decode("utf-8") for k, v in + redis_client.hgetall(tweet_id).items()} + ) + return render_template('home.html', menu='HOME', + tweets=tweets, + load_map=True) @app.route('/upload') @@ -652,6 +664,17 @@ def blog_page(): buf = get_html_body('doc/blog/'+blog_content+'.html',"https://github.com/arvados/bh20-seq-resource/blob/master/doc/blog/"+blog_content+".org") return render_template('blog.html',menu='BLOG',embed=buf,blog=blog_content) +@app.route('/feed', methods=['GET']) +def feed(): + redis_client = redis.Redis(host=os.environ.get('HOST', 'localhost'), + port=os.environ.get('PORT', 6379), + db=os.environ.get('REDIS_DB', 0)) + tweets = [redis_client.hgetall(tweet_id) + for tweet_id in redis_client.zrevrange('bh20-tweet-score:', + 0, -1)] + return render_template('feed.html', + menu='FEED', + tweets=tweets) @app.route('/about') def about_page(): -- cgit v1.2.3 From d42e6bc3fb58a087ba64427709034e0adf090524 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 10 Nov 2020 15:40:36 +0300 Subject: Fetch tweets from the correct redis queue * bh20simplewebuploader/main.py (send_home): Replace "gn2-tweet-score" with "bh20-tweet-score". --- bh20simplewebuploader/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index d3b9591..9d27879 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -257,7 +257,7 @@ def send_home(): port=os.environ.get('PORT', 6379), db=os.environ.get('REDIS_DB', 0)) tweets = [] - for tweet_id in redis_client.zrevrange('gn2-tweet-score:', + 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 -- cgit v1.2.3 From 203293363640e7f45ceaff09fb1a83f8c0f1496a Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 10 Nov 2020 15:42:00 +0300 Subject: Delete unused endpoint * bh20simplewebuploader/main.py (feed): Remove it. --- bh20simplewebuploader/main.py | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'bh20simplewebuploader/main.py') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index 9d27879..510df1c 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -664,17 +664,6 @@ def blog_page(): buf = get_html_body('doc/blog/'+blog_content+'.html',"https://github.com/arvados/bh20-seq-resource/blob/master/doc/blog/"+blog_content+".org") return render_template('blog.html',menu='BLOG',embed=buf,blog=blog_content) -@app.route('/feed', methods=['GET']) -def feed(): - redis_client = redis.Redis(host=os.environ.get('HOST', 'localhost'), - port=os.environ.get('PORT', 6379), - db=os.environ.get('REDIS_DB', 0)) - tweets = [redis_client.hgetall(tweet_id) - for tweet_id in redis_client.zrevrange('bh20-tweet-score:', - 0, -1)] - return render_template('feed.html', - menu='FEED', - tweets=tweets) @app.route('/about') def about_page(): -- cgit v1.2.3