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
master Release-20201206
Domeniko Gentner 4 years ago
parent b252f8855b
commit f1bbd262e7
  1. 34
      twitter/twitter.py

@ -53,18 +53,28 @@ class twitter:
r.raise_for_status() r.raise_for_status()
try: try:
# Get hashtag list # Get hashtag list
hashtag = r.json()[0]['entities']['hashtags'][0]['text'] tweet_tags = r.json()[0]['entities']['hashtags']
hashtags = self.credentials['hashtags']
# It's a blocklist and the hashtag is found found_not_allowed_tag = False
if self.credentials['is_blocklist'] and hashtag in self.credentials['hashtags']:
exit(0) for each in tweet_tags:
# print(each)
# It is a list of allowed hashtags and the hashtag was not found # It's a blocklist and the hashtag is found
if not self.credentials['is_blocklist'] and hashtag not in self.credentials['hashtags']: if self.credentials['is_blocklist'] and each['text'] in hashtags:
exit(0) found_not_allowed_tag = True
break
if self.credentials['omit_replies'] and r.json()[0]['in_reply_to_status_id']:
# Tweet is a reply # 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) exit(0)
except IndexError: except IndexError:

Loading…
Cancel
Save