aboutsummaryrefslogtreecommitdiff
path: root/bh20simplewebuploader
diff options
context:
space:
mode:
authorBonfaceKilz2020-12-23 16:49:35 +0300
committerBonfaceKilz2020-12-23 16:49:35 +0300
commit6035681197c42966865730462f5532bcb2704c30 (patch)
tree9595a47dc1c83e59e17e4da7d7037182589d54cf /bh20simplewebuploader
parent1b351c9ad469014350d8abb092e33c9e3215805d (diff)
downloadbh20-seq-resource-6035681197c42966865730462f5532bcb2704c30.tar.gz
bh20-seq-resource-6035681197c42966865730462f5532bcb2704c30.tar.lz
bh20-seq-resource-6035681197c42966865730462f5532bcb2704c30.zip
Abstract away for fetching feedcontent
* bh20simplewebuploader/main.py: (get_feed_items): New function. (send_home): Use get_feed_items() for fetching feed items.
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r--bh20simplewebuploader/main.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py
index 31d1b1f..b70f49a 100644
--- a/bh20simplewebuploader/main.py
+++ b/bh20simplewebuploader/main.py
@@ -248,31 +248,32 @@ 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, 9):
- # Ensure the dict always has a value; otherwise a key
- # error will be thrown by jinja
- tweet_dict = redis_client.hgetall(tweet_id)
- if tweet_dict and int(tweet_dict.get(b'score', "0")) > 0:
- tweets.append(
+ 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
- tweet_dict.items()})
-
+ feed_dict.items()})
+ return feed_items
except redis.exceptions.ConnectionError as e:
logging.warning(f"redis connect failed {e}")
pass
+
+
+@app.route('/')
+def send_home():
+ """
+ Send the front page.
+ """
return render_template('home.html', menu='HOME',
- tweets=tweets,
+ tweets=get_feed_items("bh20-tweet-score:"),
load_map=True)