reduce spam of twitter API
This commit is contained in:
parent
68144b56ca
commit
b1c5abe1f9
1 changed files with 17 additions and 7 deletions
22
main.py
22
main.py
|
@ -331,14 +331,24 @@ def start():
|
||||||
|
|
||||||
stream = Listener(keys["BEARER_TOKEN"], client)
|
stream = Listener(keys["BEARER_TOKEN"], client)
|
||||||
|
|
||||||
# Clean rules
|
# Gathering rules
|
||||||
old_rules = stream.get_rules()
|
rules = [rule for rule in create_rules(tracked_users)]
|
||||||
if (old_rules.data):
|
|
||||||
stream.delete_rules([rule.id for rule in old_rules.data])
|
# 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
|
# Add new rules
|
||||||
stream.add_rules([StreamRule(rule)
|
stream.add_rules([StreamRule(rule) for rule in rules])
|
||||||
for rule in create_rules(tracked_users)])
|
break
|
||||||
|
|
||||||
stream.filter(threaded=True, tweet_fields="author_id")
|
stream.filter(threaded=True, tweet_fields="author_id")
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue