Skip to content

Instantly share code, notes, and snippets.

@dracos
Last active May 4, 2021
Embed
What would you like to do?
Update Twitter profile pic
import os, sys
import tweepy
# config.py contains all the all-caps variables used below
from config import *
localfile = os.path.join(LOCALDIR, 'count')
try:
fp = open(localfile)
count = int(fp.read())
fp.close()
except:
count = 0
count += 1
if count > NUMPHOTOS:
count = 1
image = os.path.join(LOCALDIR, 'pic%d.jpg' % count)
if not os.path.exists(image):
image = os.path.join(LOCALDIR, 'pic%d.png' % count)
if not os.path.exists(image):
print "ERROR, couldn't find %s!" % image
sys.exit()
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
api.update_profile_image(image)
fp = open(localfile, 'w')
fp.write('%d' % count)
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment