aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2020-12-18 23:53:51 +0300
committerBonfaceKilz2020-12-18 23:53:51 +0300
commit35b1eb80cc8d0fb880c949de806c0ddba23c0fd9 (patch)
tree433e1ea607a70880c92854404cae320bcdf29be7
parent81dd50909edd74a0c5fbcd1a4fc259cf1952193d (diff)
downloadbh20-seq-resource-35b1eb80cc8d0fb880c949de806c0ddba23c0fd9.tar.gz
bh20-seq-resource-35b1eb80cc8d0fb880c949de806c0ddba23c0fd9.tar.lz
bh20-seq-resource-35b1eb80cc8d0fb880c949de806c0ddba23c0fd9.zip
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
-rw-r--r--bh20simplewebuploader/main.py12
1 files changed, 8 insertions, 4 deletions
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