From 7bf33bdc4c034b8f4a066c2240dc91713cb87b77 Mon Sep 17 00:00:00 2001 From: muskit <15199219+muskit@users.noreply.github.com> Date: Mon, 23 Jan 2023 22:37:21 -0800 Subject: [PATCH] fix rule adding, (some) random crashing --- src/listen.py | 7 ++++++- src/talent_lists.py | 3 ++- src/talenttweet.py | 3 ++- src/twapi.py | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/listen.py b/src/listen.py index 83bab82..58273d0 100644 --- a/src/listen.py +++ b/src/listen.py @@ -16,6 +16,11 @@ errors_encountered = 0 def on_response(resp): ttweet = TalentTweet.create_from_v2api_response(resp) + if ttweet is None: + print('Couldn\'t create ttweet from the response:') + print(resp) + return + tweet_username = util.get_username(ttweet.author_id) if ttweet.is_cross_company(): @@ -67,4 +72,4 @@ def run(): else: print('API stream exited gracefully.') print('Re-running listen mode...') - print(f'(Had {errors_encountered} errors so far.)') \ No newline at end of file + print(f'(Had {errors_encountered} errors so far.)') diff --git a/src/talent_lists.py b/src/talent_lists.py index 40beba1..5eb4fbf 100644 --- a/src/talent_lists.py +++ b/src/talent_lists.py @@ -54,4 +54,5 @@ def get_twitter_rules(): curr_rule = f'from:{name}' else: curr_rule = test_rule - return rules \ No newline at end of file + rules.append(curr_rule) + return rules diff --git a/src/talenttweet.py b/src/talenttweet.py index a7ad1be..0df9631 100644 --- a/src/talenttweet.py +++ b/src/talenttweet.py @@ -80,6 +80,7 @@ class TalentTweet: @staticmethod def create_from_v2api_response(resp): tweet = resp.data + if tweet is None: return None mrq = twapi.TwAPI.get_mrq(resp) rt_target = None @@ -181,4 +182,4 @@ class TalentTweet: def get_datetime_str(self): unpad = '#' if platform.system() == 'Windows' else '-' - return self.date_time.strftime(f'%b %{unpad}d %Y, %{unpad}I:%M%p (%Z)') \ No newline at end of file + return self.date_time.strftime(f'%b %{unpad}d %Y, %{unpad}I:%M%p (%Z)') diff --git a/src/twapi.py b/src/twapi.py index b03334c..e44e5f8 100644 --- a/src/twapi.py +++ b/src/twapi.py @@ -248,6 +248,7 @@ class TwAPI: print('done') except: print('error occurred trying to create main tweet, falling back to URL-main + reply screencap format') + traceback.print_exc() text += f"\n{ttweet_url}" try: print('posting main tweet...', end='')