From def7de13f1009dd84bb1c2775bc85e4bb2c4aada Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 19 Sep 2020 15:53:19 +0200 Subject: [PATCH] fix strange exception on reddit api usage data.data might be null (maybe if subreddit list is []?) --- app/reddit/lib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/reddit/lib.py b/app/reddit/lib.py index 24ca47a..ef81f9a 100644 --- a/app/reddit/lib.py +++ b/app/reddit/lib.py @@ -41,7 +41,8 @@ def fetch_reddit_post(post_id): def parse_reddit_videos(data): videos = [] - entries = sorted(data['data']['children'], + data = data['data'] or {} + entries = sorted(data.get('children',[]), key=lambda e: e['data']['score'] > 1, reverse=True) for entry in entries: -- 2.39.3