From 81dd50909edd74a0c5fbcd1a4fc259cf1952193d Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Mon, 7 Dec 2020 01:31:55 +0300 Subject: Display only 10 tweets on the feed --- bh20simplewebuploader/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bh20simplewebuploader') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index d6e5249..b7da171 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -259,7 +259,7 @@ def send_home(): tweets = [] try: for tweet_id in redis_client.zrevrange('bh20-tweet-score:', - 0, -1): + 0, 9): tweets.append( {k.decode("utf-8"): v.decode("utf-8") for k, v in redis_client.hgetall(tweet_id).items()} -- cgit v1.2.3 From 35b1eb80cc8d0fb880c949de806c0ddba23c0fd9 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 18 Dec 2020 23:53:51 +0300 Subject: Omit appending empty dicts to the list of tweets This prevents any exception thrown by jinja in the rare event when an empty tweet is stored in Redis --- bh20simplewebuploader/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'bh20simplewebuploader') diff --git a/bh20simplewebuploader/main.py b/bh20simplewebuploader/main.py index b7da171..d697918 100644 --- a/bh20simplewebuploader/main.py +++ b/bh20simplewebuploader/main.py @@ -260,10 +260,14 @@ def send_home(): try: for tweet_id in redis_client.zrevrange('bh20-tweet-score:', 0, 9): - tweets.append( - {k.decode("utf-8"): v.decode("utf-8") for k, v in - redis_client.hgetall(tweet_id).items()} - ) + # 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: + tweets.append( + {k.decode("utf-8"): v.decode("utf-8") for k, v in + tweet_dict.items()}) + except redis.exceptions.ConnectionError as e: logging.warning(f"redis connect failed {e}") pass -- cgit v1.2.3