Twitter Is Easy in Python!

0

I decided to make a twitter bot in python. It is setup to tweet a vote for Tara Strong in this year’s shorty awards as an example. The Python Twitter Tools (PTT) package makes it very easy to interface with the twitter API. All you have to do is login to http://dev.twitter.com and create a new application to the the Parameters for OAuth that allow you access to your twitter account without using the username and password. OAuth(“ACCESS TOKEN”,”ACCESS TOKEN SECRET”,”CONSUMER KEY”,”CONSUMER SECRET”) is the line where you have to fill out the parameters with your own data for the twitter account application from your applications OAuth Settings page in your application.


from twitter import *
import random, time

#Function that chooses a random adjective in a file - credit James Penguin
def random_adjective():
adjectives = open("adjectives.txt", "r").read().split("\n")
return random.choice(adjectives)

my_auth = OAuth("ACCESS TOKEN","ACCESS TOKEN SECRET","CONSUMER KEY","CONSUMER SECRET")
twit = Twitter(auth=my_auth)
i = 5
while i > 0:
adjective = random_adjective()

#this is how easy it is to tweet after OAuth is setup
twit.statuses.update(status="I nominate @tarastrong for a Shorty Award in #actress because... she is %s http://t.co/s6EaQHQW" % adjective)
#time.sleep(5)
i -= 1
print(i)

Comments

Your email address will not be published. Required fields are marked *