Skip to content

Instantly share code, notes, and snippets.

@tsraveling
Created May 7, 2017 14:58
Show Gist options
  • Save tsraveling/cea5a12f21c9c09e8f1bff2c7a2000bb to your computer and use it in GitHub Desktop.
Save tsraveling/cea5a12f21c9c09e8f1bff2c7a2000bb to your computer and use it in GitHub Desktop.
Python Twitter Bot
import random
# This file composes the tweets.
def compose():
return "tweet"
worker: python3 tweetbot.py
python-3.4.3
import os
import composer
import time
import random
import tweepy
# Set up Twitter login
CONSUMER_KEY = 'xxx'
CONSUMER_SECRET = 'xxx'
ACCESS_KEY = 'xxx'
ACCESS_SECRET = 'xxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
# Uncomment these to preview the tweets instead of actually tweeting them
#for x in range(0,20):
# tweet = composer.compose()
# print(tweet + " (%u)" % len(tweet))
#exit()
while 1:
tweet = composer.compose()
print("Composing tweet: " + tweet)
api.update_status(tweet)
base_time = 75*60
random_add = (random.randint(0,60))*60
next_time = base_time + random_add
print("Doing another one in %u minutes" % (next_time / 60))
time.sleep(next_time)
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment