def __init__(self, debug=None): if debug is None: self.DEBUG = False else: self.DEBUG = debug cached_auth = None if os.path.isfile(settings_file): with open(settings_file) as file_data: cached_auth = json.load(file_data, object_hook=from_json) if not cached_auth: ts_seed = str(int(os.path.getmtime(__file__))) # Example of how to generate a uuid. # You can generate a fixed uuid if you use a fixed value seed uuid = Client.generate_uuid(seed='{pw!s}.{usr!s}.{ts!s}'.format( **{ 'pw': username, 'usr': password, 'ts': ts_seed })) device_id = Client.generate_deviceid( seed='{usr!s}.{ts!s}.{pw!s}'.format(**{ 'pw': password, 'usr': username, 'ts': ts_seed })) # start afresh without existing auth try: self.instagram = Client( username, password, auto_patch=True, drop_incompat_keys=False, guid=uuid, device_id=device_id, ) except ClientLoginError: print('Login Error. Please check your username and password.') # stuff that you should cache cached_auth = self.instagram.settings with open(settings_file, 'w') as outfile: json.dump(cached_auth, outfile, default=to_json) else: try: # remove previous app version specific info so that we # can test the new sig key whenever there's an update for k in [ 'app_version', 'signature_key', 'key_version', 'ig_capabilities' ]: cached_auth.pop(k, None) self.instagram = Client(username, password, auto_patch=True, drop_incompat_keys=False, settings=cached_auth) except ClientCookieExpiredError: print( 'Cookie Expired. Please discard cached auth and login again.' )
# Example of how to generate a uuid. # You can generate a fixed uuid if you use a fixed value seed uuid = Client.generate_uuid(seed='%(pw)s.%(usr)s.%(ts)s' % { 'pw': args.username, 'usr': args.password, 'ts': ts_seed }) else: uuid = args.uuid if not args.device_id: # Example of how to generate a device id. # You can generate a fixed device id if you use a fixed value seed device_id = Client.generate_deviceid(seed='%(usr)s.%(ts)s.%(pw)s' % { 'pw': args.password, 'usr': args.username, 'ts': ts_seed }) else: device_id = args.device_id # Optional. You can custom the device settings instead of using the default one my_custom_device = { 'manufacturer': 'Samsung', 'model': 'maguro', 'device': 'Galaxy Nexus', 'android_release': '4.3', 'android_version': 18, 'dpi': '320dpi', 'resolution': '720x1280', 'chipset': 'qcom'