Skip to content

Instantly share code, notes, and snippets.

@karno
Created May 12, 2015 13:23
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 karno/74843b11d408f2e9ec73 to your computer and use it in GitHub Desktop.
Save karno/74843b11d408f2e9ec73 to your computer and use it in GitHub Desktop.

HOW TO USE

  1. RENAME config.example.py TO config.py
  2. FILL consumer key/secret AND token key/secret IN config.py
  3. WRITE candidates of your profiles IN profiles
  4. $ python switchprof.py [KEY]
#!/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"
},
]
}
#!/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