From f840a456af772320ce6a7393fd73e07705177bd4 Mon Sep 17 00:00:00 2001 From: jacktjong Date: Fri, 4 Nov 2022 22:21:19 +0100 Subject: [PATCH] Cleaner Python Code --- dashboard.py | 62 +++++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/dashboard.py b/dashboard.py index e62eb14..43f9025 100644 --- a/dashboard.py +++ b/dashboard.py @@ -41,51 +41,25 @@ def words(message): @event('tweet') def generate_tweet(ctx, e): tweet = dict(e.data) + pops = [ + "display_text_range", + "in_reply_to_status_id", + "in_reply_to_status_id_str", + "in_reply_to_user_id", + "in_reply_to_user_id_str", + "in_reply_to_screen_name", + "geo", + "coordinates", + "place", + "contributors", + "is_quote_status" + ] try: - try: - tweet.pop("display_text_range") - except KeyError: - pass - try: - tweet.pop("in_reply_to_status_id") - except KeyError: - pass - try: - tweet.pop("in_reply_to_status_id_str") - except KeyError: - pass - try: - tweet.pop("in_reply_to_user_id") - except KeyError: - pass - try: - tweet.pop("in_reply_to_user_id_str") - except KeyError: - pass - try: - tweet.pop("in_reply_to_screen_name") - except KeyError: - pass - try: - tweet.pop("geo") - except KeyError: - pass - try: - tweet.pop("coordinates") - except KeyError: - pass - try: - tweet.pop("place") - except KeyError: - pass - try: - tweet.pop("contributors") - except KeyError: - pass - try: - tweet.pop("is_quote_status") - except KeyError: - pass + for x in pops: + try: + tweet.pop(x) + except KeyError: + pass except: pass # base sample on previous one