diff options
author | BonfaceKilz | 2020-11-10 03:42:12 +0300 |
---|---|---|
committer | BonfaceKilz | 2020-11-10 03:42:12 +0300 |
commit | 2e2e2280f59b783759b7b70d410fb7a5c59206d5 (patch) | |
tree | 5ba26a9e8c9be51b11a9b4dd7c9cca727676ec58 /bh20simplewebuploader/main.py | |
parent | 59b4c0ff845686ce2e58e0c2df126f1bae514ab1 (diff) | |
download | bh20-seq-resource-2e2e2280f59b783759b7b70d410fb7a5c59206d5.tar.gz bh20-seq-resource-2e2e2280f59b783759b7b70d410fb7a5c59206d5.tar.lz bh20-seq-resource-2e2e2280f59b783759b7b70d410fb7a5c59206d5.zip |
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.
Diffstat (limited to 'bh20simplewebuploader/main.py')
-rw-r--r-- | bh20simplewebuploader/main.py | 27 |
1 files changed, 25 insertions, 2 deletions
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(): |