Skip to content

Instantly share code, notes, and snippets.

@dracos
Last active May 4, 2021 06:11
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 dracos/e152749b3fe499eab3ffc12a5a30040c to your computer and use it in GitHub Desktop.
Save dracos/e152749b3fe499eab3ffc12a5a30040c to your computer and use it in GitHub Desktop.
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