Last active
August 29, 2015 13:59
-
-
Save Robaum/10485494 to your computer and use it in GitHub Desktop.
Simple twitter bot with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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