reduce spam of twitter API
This commit is contained in:
parent
68144b56ca
commit
b1c5abe1f9
1 changed files with 17 additions and 7 deletions
24
main.py
24
main.py
|
@ -331,14 +331,24 @@ def start():
|
|||
|
||||
stream = Listener(keys["BEARER_TOKEN"], client)
|
||||
|
||||
# Clean rules
|
||||
old_rules = stream.get_rules()
|
||||
if (old_rules.data):
|
||||
stream.delete_rules([rule.id for rule in old_rules.data])
|
||||
# Gathering rules
|
||||
rules = [rule for rule in create_rules(tracked_users)]
|
||||
|
||||
# Check if rules already exists
|
||||
old_rules = stream.get_rules().data
|
||||
old_rules_values = [rule.value for rule in old_rules]
|
||||
# Same amount of rules
|
||||
if len(old_rules_values) == len(rules):
|
||||
for rule in rules:
|
||||
# Check if Twitter doesn't know the rule and change rules if needed
|
||||
if rule not in old_rules_values:
|
||||
# Clean old rules
|
||||
stream.delete_rules([rule.id for rule in old_rules])
|
||||
|
||||
# Add new rules
|
||||
stream.add_rules([StreamRule(rule) for rule in rules])
|
||||
break
|
||||
|
||||
# Add new rules
|
||||
stream.add_rules([StreamRule(rule)
|
||||
for rule in create_rules(tracked_users)])
|
||||
stream.filter(threaded=True, tweet_fields="author_id")
|
||||
|
||||
|
||||
|
|
Reference in a new issue