def on_status(self, status): if ( status.user.screen_name.lower() in self.relevant_users and not status.text.startswith("RT ") and status.in_reply_to_screen_name is None ): log.debug("On status from tweepy: %s", status.text) tweet_message = stringify_tweet(status) self.bot.say(f"B) New cool tweet from {status.user.screen_name}: {tweet_message}")
def get_last_tweet(self, username): if self.twitter_client: try: public_tweets = self.twitter_client.user_timeline(username) for tweet in public_tweets: if not tweet.text.startswith("RT ") and tweet.in_reply_to_screen_name is None: # Tweepy returns naive datetime object (but it's always UTC) # .replace() makes it timezone-aware :) created_at = tweet.created_at.replace(tzinfo=datetime.timezone.utc) tweet_message = stringify_tweet(tweet) return f"{tweet_message} ({time_since(utils.now().timestamp(), created_at.timestamp(), time_format='short')} ago)" except Exception: log.exception("Exception caught while getting last tweet") return "FeelsBadMan" else: return "Twitter not set up FeelsBadMan" return "FeelsBadMan"