I am trying to make a Twitter bot that will reply to tweet automatically but I do not want it to reply to tweets it has already replied to so I am trying to have the tweet IDs saved to a text document and have the bot reference it for the last seen ID but it is not updating the text document.
FILE_NAME = 'last_seen.txt'
def read_last_seen(FILE_NAME):
file_read = open(FILE_NAME, 'r')
last_seen_id = int(file_read.read().strip())
file_read.close()
return last_seen_id
def store_last_seen(FILE_NAME, last_seen_id):
file_write = open(FILE_NAME, 'w')
file_write.write(str(last_seen_id))
file_write.close()
return
tweets = api.mentions_timeline(read_last_seen(FILE_NAME), tweet_mode='extended')
for tweet in reversed(tweets):
if '#botting' in tweet.full_text.lower():
print(str(tweet.id) + ' - ' + tweet.full_text)
api.update_status('@' + tweet.user.screen_name + ' This is a bot.', tweet.id)
store_last_seen(FILE_NAME, tweet.id)