Skip to content

Instantly share code, notes, and snippets.

@amanda
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amanda/bc8f130c4af89cdf979d to your computer and use it in GitHub Desktop.
Save amanda/bc8f130c4af89cdf979d to your computer and use it in GitHub Desktop.
Skeleton code for Twitter bot built using Python/Twython
#!/usr/bin/env python
from twython import Twython, TwythonError
import os
import time
'''twitter creds and setup'''
CONSUMER_KEY = os.getenv('CONSUMER_KEY')
CONSUMER_SECRET = os.getenv('CONSUMER_SECRET')
OAUTH_TOKEN = os.getenv('OAUTH_TOKEN')
OAUTH_SECRET = os.getenv('OAUTH_SECRET')
'''twitter client setup'''
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET)
def make_tweet():
'''logic for generating tweet text
goes here, returns tweet str to post'''
pass
def run():
'''post to twitter and runs the bot
to tweet at a specified interval'''
status = make_tweet()
twitter.update_status(status=status)
time.sleep(3600) # once per hour, change this if you want
if __name__ == '__main__':
while True:
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment