def get_latest_tweet(self):
"""Checks the twitter handle for new tweets.
If there has been a new tweet, it will return the Tweet
to be checked for companies"""
try:
latest_tweet = self.api.user_timeline(screen_name=self.handle, count=1)[0]
tweet = latest_tweet.text.encode('ascii', 'ignore').decode('utf-8') # Removes emjois
with open(f'{LATEST_TWEET}{self.handle}.txt', "r") as f:
old_tweet = f.read()
if tweet != old_tweet:
with open(f'{LATEST_TWEET}{self.handle}.txt', 'w') as f:
f.write(tweet)
self.tweet_id = latest_tweet.id_str
self.tweet = tweet
return tweet
except tweepy.TweepError as error:
logging.debug(error)
评论列表
文章目录