From f351e477e324016d028646560ebaf0b0f6e79df8 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 9 Aug 2022 02:32:34 +0200 Subject: [PATCH] fix nonetype --- main.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 8ae8996..9ebe3c1 100644 --- a/main.py +++ b/main.py @@ -336,18 +336,26 @@ def start(): # Check if rules already exists old_rules = stream.get_rules().data - old_rules_values = [rule.value for rule in old_rules] + old_rules_values = [] + if old_rules: + old_rules_values = [rule.value for rule in old_rules] + need_changes = False # 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]) + need_changes = True break + else: + need_changes = True + + if need_changes: + # 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]) # Apply the filter stream.filter(threaded=True, tweet_fields="author_id")