Beispiel #1
0
def login(api: Client):
    username = pil.ig_user
    try:
        api.login()
    except (ClientCheckpointRequiredError, ClientChallengeRequiredError) as e:
        challenge_url = e.challenge_url

        challenge_pattern = r'.*challenge/(?P<account_id>\d.*)/(?P<identifier>\w.*)/'
        match = re.search(challenge_pattern, challenge_url)
        if not match:
            raise ClientError('Unable to parse challenge')

        match_dict = match.groupdict()
        account_id = match_dict['account_id']
        identifier = match_dict['identifier']

        res = api.choose_confirm_method(
            account_id,
            '1')  # confirm_method param has default value 1, you can pass 0
        magic_code = get_code_from_email(username)
        if magic_code:
            code = magic_code
        else:
            code = input('Enter code from email: ')
        api.send_challenge(account_id, identifier, code)
        json.dump(cache_settings, outfile, default=to_json)
        print('SAVED: {0!s}'.format(new_settings_file))


username = '******'
password = '******'
settings_file = '/path/to/file/settings_{}.json'.format(username)

api = Client(username,
             password,
             on_login=lambda x: onlogin_callback(x, settings_file))
try:
    api.login()
except ClientCheckpointRequiredError as e:
    challenge_url = e.challenge_url

    challenge_pattern = r'.*challenge/(?P<account_id>\d.*)/(?P<identifier>\w.*)/'
    match = re.search(challenge_pattern, challenge_url)
    if not match:
        raise ClientError('Unable to parse challenge')

    match_dict = match.groupdict()
    account_id = match_dict['account_id']
    identifier = match_dict['identifier']

    res = api.choose_confirm_method(
        account_id,
        identifier)  # confirm_method param has default value 1, you can pass 0
    code = input('Enter code from email: ')
    api.send_challenge(account_id, identifier, code)