Exemplo n.º 1
0
def level_up_account(args, location, accounts, errors):
    while True:
        try:
            # Loop the queue.
            try:
                (account, error_count) = accounts.get(False)
            except Empty:
                break

            log.info('Starting account %s', account['username'])
            status = {
                'type': 'Worker',
                'message': 'Creating thread...',
                'success': 0,
                'fail': 0,
                'noitems': 0,
                'skip': 0,
                'captcha': 0,
                'username': '',
                'proxy_display': None,
                'proxy_url': None,
            }
            api = setup_api(args, status, account)
            api.set_position(*location)
            key = key_scheduler.next()
            api.activate_hash_server(key)
            check_login(args, account, api, status['proxy_url'])
            log.info('Account %s, level %d.', account['username'],
                     account['level'])
            (error, forts) = get_location_forts(api, account, location)
            if error:
                errors[error].append(account)
                accounts.task_done()
                continue
            log.info('%d stops in range', len(forts))
            for fort in forts:
                if pokestop_spinnable(fort, location):
                    spin_pokestop(api, account, args, fort, location)
            log.info('Ended with account %s.', account['username'])
            log.info('Account %s, level %d.', account['username'],
                     account['level'])
        except TooManyLoginAttempts:
            errors[ErrorType.login_error].append(account)
        except AccountBannedException:
            errors[ErrorType.banned].append(account)
        except Exception as e:
            if error_count < 2:
                log.exception('Exception in worker: %s. retrying.', e)
                accounts.put((account, error_count + 1))
            else:
                errors[ErrorType.generic].append(account)

        accounts.task_done()
Exemplo n.º 2
0
def level_up_account(args, location, accounts, errors):
    while True:
        try:
            # Loop the queue.
            try:
                (account, error_count) = accounts.get(False)
            except Empty:
                break

            log.info('Starting account %s', account['username'])
            status = {
                'type': 'Worker',
                'message': 'Creating thread...',
                'success': 0,
                'fail': 0,
                'noitems': 0,
                'skip': 0,
                'captcha': 0,
                'username': '',
                'proxy_display': None,
                'proxy_url': None,
            }

            api = setup_api(args, status, account)
            key = key_scheduler.next()

            api.set_position(*location)
            api.activate_hash_server(key)
            check_login(args, account, api, status['proxy_url'])

            log.info('Logged in account %s, level %d.', account['username'],
                     account['level'])

            (error, forts) = get_location_forts(api, account, location)

            if error:
                errors[error].append(account)
                accounts.task_done()
                continue

            spinnable_pokestops = filter(
                lambda fort: pokestop_spinnable(fort, location), forts)

            # No stops in spin range.
            first_fort = forts[0]
            if not spinnable_pokestops:
                log.critical(
                    'No Pokestops in spinnable range. Please move'
                    " the location. There's a Pokestop at"
                    ' %s, %s.', first_fort.latitude, first_fort.longitude)
                os._exit(1)

            # Past this point, guaranteed to have a spinnable stop.
            fort = spinnable_pokestops[0]
            spin_pokestop(api, account, args, fort, location)

            log.info('Spun Pokestop with account %s, level %d.',
                     account['username'], account['level'])
        except TooManyLoginAttempts:
            errors[ErrorType.login_error].append(account)
        except AccountBannedException:
            errors[ErrorType.banned].append(account)
        except Exception as e:
            if error_count < 2:
                log.exception('Exception in worker: %s. Retrying.', e)
                accounts.put((account, error_count + 1))
            else:
                errors[ErrorType.generic].append(account)

        accounts.task_done()