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