mardi 5 avril 2016

Removing random line from text file - Python

I've just set up a twitter bot. It pulls it tweets at random from a text file and tweets it. Becuase Twitter does not allow duplicate tweets, how can I delete the tweet from the text file so it doesn't try and tweet it again? the relevant bits of code look like this:

while True:
 lines = open('tweets.txt').read().splitlines()
 tweet = random.choice(lines)
 twitter.update_status(status=tweet)
 print (tweet)
 sleepTime = random.randint(30, 60)
 time.sleep(sleepTime)




Aucun commentaire:

Enregistrer un commentaire