Created
February 5, 2015 17:32
-
-
Save karno/08ab54432fe5cfd4c266 to your computer and use it in GitHub Desktop.
required: python3, https://github.com/sixohsix/twitter
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
#!/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