Dov Alperin
Dov Alperin

Reputation: 39

Python tweetbot follow code won't work

I am building a tweetbot and I keep getting an error when running my code this only showed up after I tried to add code to follow anyone who follows me (I delete tweets from the text file before running again, the error is due to the part that follows people back):

import tweepy, time

CONSUMER_KEY = 'KEY'
CONSUMER_SECRET = 'KEY'
ACCESS_KEY = 'Key'
ACCESS_SECRET = 'Key'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

for follower in tweepy.Cursor(api.followers).items():
    follower.follow()

filename=open('file.txt','r')
tweets=filename.readlines()
filename.close()

for line in tweets:
    api.update_status(line)
    print line, time.strftime("%H:%M:%S")
    time.sleep(120)

Here is the error

File "tweetbot.py", line 19, in <module>
api.update_status(line)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/tweepy/api.py", line 194, in update_status
)(post_data=post_data, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 245, in _call
return method.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 229, in execute
raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{u'message': u'Status is a duplicate.', u'code': 187}]

Upvotes: 0

Views: 259

Answers (1)

user6457192
user6457192

Reputation:

Tweepy does not let you tweet if you have the same tweet...

So you can do this -

for status in tweepy.Cursor(api.user_timeline).items():
        api.destroy_status(status.id)

Upvotes: 2

Related Questions