Skip to content

Instantly share code, notes, and snippets.

@karno
Created February 5, 2015 17:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karno/08ab54432fe5cfd4c266 to your computer and use it in GitHub Desktop.
Save karno/08ab54432fe5cfd4c266 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from twitter import *
from config import *
def main(arg: str):
api = Twitter(auth=OAuth(
config['token']['key'],
config['token']['secret'],
config['consumer']['key'],
config['consumer']['secret']))
# argument is numeric index or key string
prof = None
# find matching profile
for cp in config['profiles']:
if cp['key'] == arg:
prof = cp
break
if prof is None:
# find by index
try:
config['profiles'][int(arg)]
except ValueError:
prof = None
if prof is None:
print('invalid argument: ' + arg)
exit(-1)
print('uploading profile image...')
with open(prof['image'], "rb") as image:
params = {"image": image.read()}
api.account.update_profile_image(**params)
print('updating profile...')
api.account.update_profile(
name=prof['name'],
url=prof['url'],
location=prof['location'],
description=prof['description'])
print('successfully changed to ' + prof['name'] + '.')
exit(0);
if __name__ == '__main__':
if len(sys.argv) >= 2:
main(sys.argv[1])
else:
main('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment