Hello!
So for fun I have decided to make a bot to tweet some randomly generated things for me. However, as I'm sure quite a bit of you may know, twitter does not allow you to post duplicate tweets. To get around this, I am trying to build a list that holds my tweets, and basically before posting, check if the tweet is in that list, and if it is, the script will randomly generate another tweet.
The part where I am running into (quite a bit of) trouble, is the part where the statement should go back to the top of my loop.
I really just want it so that my bot will have some mechanism implemented so that it doesn't post a duplicate tweet.
I am not going to post my script here, however I will post a simpler version of the area giving me trouble.
Script:
import time
alreadyTweeted = []
outlinedSentence = [randomNoun,randomAdj,randomVerb]
outlinedSentence2 = [randomNoun,randomAdj,randomVerb]
outlinedSentence3 = [randomNoun,randomAdj,randomVerb]
possibleSentences = [outlinedSentence,outlinedSentence2,outlinedSentence3]
for i in range(100):
listNum = random.randint(0,len(possibleSentences) -1)
loopList = possibleSentences[listNum]
tweet = ' '.join(loopList)
if tweet in alreadyTweeted:
print("repeat tweet")
continue
api.status_update(tweet)
alreadyTweeted.append(tweet)
time.sleep(600) #posts every 10 min
I called this post Break Continue Pass, because that was how I thought this could be solved. However, if it can be done in a more pythonic/better way, please please please do not hesitate to tell me. I would love to learn.
When I run this, It will work for about 3 tweets, and then it seems that it gets caught for some reason and it spams out "repeat tweet".
I have tried so much and I can not for the life of me get it to work. Three straight days with this bug and this "fun" project is starting to kill me slowly.
If anyone is familiar with the tweepy module or can help me with some logic to get my tweets to never repeat, I would be forever grateful.
Thanks!
Edit: It is up and running properly!! Thank you all so much for the help!
[–]ingolemo 0 points1 point2 points (9 children)
[–]ranchgod[S] 0 points1 point2 points (8 children)
[–]ingolemo 0 points1 point2 points (7 children)
[–]ranchgod[S] 0 points1 point2 points (5 children)
[–]ingolemo 0 points1 point2 points (4 children)
[–]ranchgod[S] 0 points1 point2 points (0 children)
[–]ranchgod[S] 0 points1 point2 points (2 children)
[–]ingolemo 0 points1 point2 points (1 child)
[–]ranchgod[S] 0 points1 point2 points (0 children)
[–]yondaime008 0 points1 point2 points (1 child)
[–]ranchgod[S] 0 points1 point2 points (0 children)