From f1bbd262e7591c9ceeb3556698f2b48d972db2e0 Mon Sep 17 00:00:00 2001 From: Domeniko Gentner Date: Sun, 6 Dec 2020 09:17:30 +0100 Subject: [PATCH] Update 06/12/2020 * Added new configuration options, please update your twitter.json after updating! Please see ./etc/twitter.json for changes. * The hashtag list can now act as block list or include list, depending on `is_blocklist` * Replies can now be ignored by setting `omit_replies` to true. * Fixed bug where only one hashtag was processed --- twitter/twitter.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/twitter/twitter.py b/twitter/twitter.py index 5e40523..e65262f 100644 --- a/twitter/twitter.py +++ b/twitter/twitter.py @@ -53,18 +53,28 @@ class twitter: r.raise_for_status() try: # Get hashtag list - hashtag = r.json()[0]['entities']['hashtags'][0]['text'] - - # It's a blocklist and the hashtag is found - if self.credentials['is_blocklist'] and hashtag in self.credentials['hashtags']: - exit(0) - - # It is a list of allowed hashtags and the hashtag was not found - if not self.credentials['is_blocklist'] and hashtag not in self.credentials['hashtags']: - exit(0) - - if self.credentials['omit_replies'] and r.json()[0]['in_reply_to_status_id']: - # Tweet is a reply + tweet_tags = r.json()[0]['entities']['hashtags'] + hashtags = self.credentials['hashtags'] + found_not_allowed_tag = False + + for each in tweet_tags: + # print(each) + # It's a blocklist and the hashtag is found + if self.credentials['is_blocklist'] and each['text'] in hashtags: + found_not_allowed_tag = True + break + + # It is a list of allowed hashtags and the hashtag was found + if not self.credentials['is_blocklist'] and each['text'] in hashtags: + found_not_allowed_tag = False + break + + if self.credentials['omit_replies'] and r.json()[0]['in_reply_to_status_id']: + # Tweet is a reply + found_not_allowed_tag = True + break + + if found_not_allowed_tag: exit(0) except IndexError: