Created
September 16, 2015 15:12
-
-
Save karno/e7ed36f91033d2caf34e to your computer and use it in GitHub Desktop.
Masquerade system core program
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 switch_profile(key: str): | |
api = Twitter(auth=OAuth( | |
config['token']['key'], | |
config['token']['secret'], | |
config['consumer']['key'], | |
config['consumer']['secret'])) | |
# keyument is numeric index or key string | |
prof = None | |
# find matching profile | |
for cp in config['profiles']: | |
if cp['key'] == key: | |
prof = cp | |
break | |
if prof is None: | |
# find by index | |
try: | |
config['profiles'][int(key)] | |
except ValueError: | |
prof = None | |
if prof is None: | |
print('invalid keyument: ' + key) | |
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']) | |
if 'auto_intro' in prof and prof['auto_intro'] == True and \ | |
'intro' in prof and prof['intro'] != None: | |
print('tweeting introduction...') | |
api.statuses.update(status=prof['intro']) | |
print('successfully changed to ' + prof['name'] + '.') | |
exit(0); | |
if __name__ == '__main__': | |
if len(sys.argv) >= 2: | |
switch_profile(sys.argv[1]) | |
else: | |
main('') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment