Hi,
i want to make my own twitter bot with twython and need a lil help now.
Here is the code:
from twython import Twython, TwythonError
import time
import random
#Twitter Daten
apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
apiSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
accessToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
accessTokenSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
twitter = Twython(apiKey,apiSecret,accessToken,accessTokenSecret)
#accountname read
adatei = open("./twitter/account_name.txt")
accountname = afile.readline()
afile.close()
#Small list of Tweets to Tweet
list = [
"My Account www.test.com/"+accountname+" :)",
"Hi here at www.test.com/"+accountname+" :)",
"example example www.exaple.com/"+accountname+" :)",
"my facebook www.facebook.com/"+I got following erroraccountname+" :)",
]
#This is called a while loop.
while True:
try:
if len(list) > 0:
toTweet = list[random.randint(0,len(list))-1]
photo = open("/Twitter/pictures/"+accountname+".jpg", 'rb')
response = twitter.upload_media(media=photo)
twitter.update_status(status=toTweet,media_ids=[response['media_id']])
time.sleep(3600)
#Oops! twitter.update_status should all be on one line!
twitter.update_status(status="No new news atm =(")
break
except TwythonError as e:
print ("e")
If u can see, i have a txt-file with names inside and a directory with photos. I want that the bot takes the first name from the file and add them to the tweet in the list section and also upload a picture with the same name as the name from the picture.
I get following error : IOError: [Errno 2] No such file or directory: '/twitter/pictures/name\n.jpg'
How can i remove the \n ? And how i can remove after the tweet is sent the accountname from the txt-file
Hope someone can help me her.