- RENAME config.example.py TO config.py
- FILL consumer key/secret AND token key/secret IN config.py
- WRITE candidates of your profiles IN profiles
- $ python switchprof.py [KEY]
Created
May 12, 2015 13:23
-
-
Save karno/74843b11d408f2e9ec73 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -*- | |
config = { | |
"consumer": { | |
"key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", | |
"secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", | |
}, | |
"token": { | |
"key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", | |
"secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", | |
}, | |
"profiles": [ | |
# { | |
# "key": "", | |
# "name: "", | |
# "url": "", | |
# "location": "", | |
# "description": "", | |
# "image": "" | |
# } | |
{ | |
"key": "key_for_specify_this", | |
"name": "あなたのなまえ", | |
"url": "http://example.com/?set_your_url", | |
"location": "YOUR LOCATION", | |
"description": "INPUT YOUR DESCRIPTION", | |
"image": "C:\\SET\\PATH\\OF\\YOUR\\PROFILE\\IMAGE.JPG" | |
}, | |
] | |
} |
This file contains hidden or 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