Instantly share code, notes, and snippets.

@Robaum /bot.py
Last active Aug 29, 2015

Embed
What would you like to do?
Simple twitter bot with python
# We use the twython lib to post in twitter
from twython import Twython
import time, sys
# Twitter Keys
# API key
APP_KEY = ''
# Secret API key
APP_SECRET = ''
# Access token
OAUTH_TOKEN = ''
# Access Token Secret
OAUTH_TOKEN_SECRET = ''
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
# I read a file with the song "Pasito tun tun" for flavor text
argfile = str(sys.argv[1])
filename=open(argfile,'r')
f=filename.readlines()
filename.close()
# For when we reach the max
imgCount = 0
songCount = 0
imgMax = 100
# While we still have images keep posting
while imgCount < imgMax:
# If you want to just post some text you can use
twitter.update_status(status="Hello World!")
# If you want to post text and a photo use
photo = open('test.png', 'rb')
twitter.update_status_with_media(status='Checkout this cool image!', media=photo)
# For our bot we post a part of the song and the next img
photoRisa = open(str(imgCount)+'.png', 'rb')
twitter.update_status_with_media(status=f[songCount], media=photoRisa)
# Increase the counts
imgCount = imgCount + 1
songCount = songCount + 1
# Repeat the text when we reach the end of the file
if songCount >= len(f):
songCount = 0
# Tweet every second
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment