def random_tweet():
# build a twitter list of five possible tweets
tweet_list = [
'Charm was a scheme for making strangers like and trust a person immediately, no matter what the charmer had in mind.',
"There is no good reason good can't triumph over evil, if only angels will get organized along the lines of the mafia.",
"Shrapnel was invented by an Englishman of the same name. Don't you wish you could have something named after you?",
"If your brains were dynamite there wouldn't be enough to blow your hat off.",
"And so on."
]
x = 0
# create a loop to tweet twice
while x < 2:
try:
# generate a random variable between 0 and 4
rand = random.randint(0, 4)
# use that random variable to grab an item from tweet_list
api.update_status(tweet_list[rand])
# take a 30-second break so we don't overwhelm our followers
sleep(30)
#increment our counter
x += 1
# if there's an error, catch it instead of crashing and print out the error message
except tweepy.TweepError, e:
print 'Error sending tweet:', e[0][0]['message']
# a function to tweet a gif
评论列表
文章目录