|
@@ -34,33 +34,34 @@ def from_json(json_object):
|
|
|
return json_object
|
|
|
|
|
|
|
|
|
-def onlogin_callback(api, settings_file):
|
|
|
+def onlogin_callback(api, cookie_file):
|
|
|
cache_settings = api.settings
|
|
|
- with open(settings_file, 'w') as outfile:
|
|
|
+ with open(cookie_file, 'w') as outfile:
|
|
|
json.dump(cache_settings, outfile, default=to_json)
|
|
|
- log('[I] New auth cookie file was made: {0!s}'.format(settings_file), "GREEN")
|
|
|
+ log('[I] New user cookie file was made: {0!s}'.format(cookie_file), "GREEN")
|
|
|
|
|
|
|
|
|
-def login(username, password, show_cookie_expiry, ignore_existing_cookie):
|
|
|
+def login(username, password, show_cookie_expiry, force_use_login_args):
|
|
|
device_id = None
|
|
|
try:
|
|
|
- if ignore_existing_cookie:
|
|
|
+ if force_use_login_args:
|
|
|
+ log("[I] Overriding standard login with -u and -p arguments...", "GREEN")
|
|
|
api = Client(
|
|
|
username, password)
|
|
|
else:
|
|
|
- settings_file = username + ".json"
|
|
|
- if not os.path.isfile(settings_file):
|
|
|
+ cookie_file = "{}.json".format(username)
|
|
|
+ if not os.path.isfile(cookie_file):
|
|
|
# settings file does not exist
|
|
|
- log('[W] Unable to find auth cookie file: {0!s}'.format(settings_file), "YELLOW")
|
|
|
+ log('[W] Unable to find user cookie file: {0!s}'.format(cookie_file), "YELLOW")
|
|
|
|
|
|
# login new
|
|
|
api = Client(
|
|
|
username, password,
|
|
|
- on_login=lambda x: onlogin_callback(x, settings_file))
|
|
|
+ on_login=lambda x: onlogin_callback(x, cookie_file))
|
|
|
else:
|
|
|
- with open(settings_file) as file_data:
|
|
|
+ with open(cookie_file) as file_data:
|
|
|
cached_settings = json.load(file_data, object_hook=from_json)
|
|
|
- # log('[I] Using settings file: {0!s}'.format(settings_file), "GREEN")
|
|
|
+ # log('[I] Using settings file: {0!s}'.format(cookie_file), "GREEN")
|
|
|
|
|
|
device_id = cached_settings.get('device_id')
|
|
|
# reuse auth settings
|
|
@@ -76,7 +77,7 @@ def login(username, password, show_cookie_expiry, ignore_existing_cookie):
|
|
|
api = Client(
|
|
|
username, password,
|
|
|
device_id=device_id,
|
|
|
- on_login=lambda x: onlogin_callback(x, settings_file))
|
|
|
+ on_login=lambda x: onlogin_callback(x, cookie_file))
|
|
|
|
|
|
except ClientLoginError as e:
|
|
|
seperator("GREEN")
|
|
@@ -91,17 +92,22 @@ def login(username, password, show_cookie_expiry, ignore_existing_cookie):
|
|
|
except Exception as e:
|
|
|
if (str(e).startswith("unsupported pickle protocol")):
|
|
|
log("[W] This cookie file is not compatible with Python {}.".format(sys.version.split(' ')[0][0]), "YELLOW")
|
|
|
- log("[W] Please delete your cookie file '" + username + ".json' and try again.", "YELLOW")
|
|
|
+ log("[W] Please delete your cookie file '{}.json' and try again.".format(useranem), "YELLOW")
|
|
|
else:
|
|
|
log('[E] Unexpected Exception: {0!s}'.format(e), "RED")
|
|
|
seperator("GREEN")
|
|
|
sys.exit(99)
|
|
|
+ except KeyboardInterrupt as e:
|
|
|
+ seperator("GREEN")
|
|
|
+ log("[W] The user authentication has been aborted.", "YELLOW")
|
|
|
+ seperator("GREEN")
|
|
|
+ sys.exit(0)
|
|
|
|
|
|
- log('[I] Using login cookie for "' + api.authenticated_user_name + '".', "GREEN")
|
|
|
- if show_cookie_expiry.title() == 'True' and not ignore_existing_cookie:
|
|
|
+ log('[I] Using user cookie for "{:s}".'.format(str(api.authenticated_user_name)), "GREEN")
|
|
|
+ if show_cookie_expiry.title() == 'True' and not force_use_login_args:
|
|
|
try:
|
|
|
cookie_expiry = api.cookie_jar.auth_expires
|
|
|
- log('[I] Login cookie expiry date: {0!s}'.format(datetime.datetime.fromtimestamp(cookie_expiry).strftime('%Y-%m-%d at %I:%M:%S %p')), "GREEN")
|
|
|
+ log('[I] User cookie expiry date: {0!s}'.format(datetime.datetime.fromtimestamp(cookie_expiry).strftime('%Y-%m-%d at %I:%M:%S %p')), "GREEN")
|
|
|
except AttributeError as e:
|
|
|
log('[W] An error occurred while getting the cookie expiry date: {0!s}'.format(e), "YELLOW")
|
|
|
|