async def main(): try: if hasattr(config, 'AUTHKEY'): authkey = config.AUTHKEY else: authkey = b'm3wtw0' if hasattr(config, 'HASH_KEY'): HASH_KEY = config.HASH_KEY else: HASH_KEY = None class AccountManager(BaseManager): pass AccountManager.register('captcha_queue') AccountManager.register('extra_queue') manager = AccountManager(address=get_address(), authkey=authkey) manager.connect() captcha_queue = manager.captcha_queue() extra_queue = manager.extra_queue() driver = webdriver.Chrome() driver.set_window_size(803, 807) while not captcha_queue.empty(): account = captcha_queue.get() username = account.get('username') location = account.get('location') if location and location != (0, 0, 0): lat = location[0] lon = location[1] try: alt = location[2] except IndexError: alt = random_altitude() else: lat = uniform(LAT_MEAN - 0.001, LAT_MEAN + 0.001) lon = uniform(LON_MEAN - 0.001, LON_MEAN + 0.001) alt = random_altitude() try: device_info = get_device_info(account) api = PGoApi(device_info=device_info) if HASH_KEY: api.activate_hash_server(HASH_KEY) api.set_position(lat, lon, alt) authenticated = False if account.get('provider') == 'ptc' and account.get('refresh'): api._auth_provider = AuthPtc() api._auth_provider.set_refresh_token( account.get('refresh')) api._auth_provider._access_token = account.get('auth') api._auth_provider._access_token_expiry = account.get( 'expiry') if api._auth_provider.check_access_token(): api._auth_provider._login = True authenticated = True if not authenticated: await api.set_authentication(username=username, password=account['password'], provider=account.get( 'provider', 'ptc')) request = api.create_request() request.download_remote_config_version(platform=1, app_version=5302) request.check_challenge() request.get_hatched_eggs() request.get_inventory() request.check_awarded_badges() request.download_settings() response = await request.call() account['time'] = time() if response['status_code'] == 3: print('{} appears to be banned.'.format(username)) continue responses = response['responses'] challenge_url = responses['CHECK_CHALLENGE']['challenge_url'] timestamp = responses.get('GET_INVENTORY', {}).get('inventory_delta', {}).get('new_timestamp_ms') account['location'] = lat, lon, alt account['inventory_timestamp'] = timestamp if challenge_url == ' ': account['captcha'] = False print('No CAPTCHA was pending on {}.'.format(username)) extra_queue.put(account) else: if await solve_captcha(challenge_url, api, driver, timestamp): account['time'] = time() account['captcha'] = False print( 'Solved CAPTCHA for {}, putting back in rotation.'. format(username)) extra_queue.put(account) else: account['time'] = time() print('Failed to solve for {}'.format(username)) captcha_queue.put(account) except KeyboardInterrupt: captcha_queue.put(account) break except KeyError: print( 'Unexpected or empty response for {}, putting back on queue.' .format(username)) captcha_queue.put(account) try: print(response) except Exception: pass await sleep(3) except (ex.AuthException, ex.AuthTokenExpiredException) as e: print('Authentication error on {}: {}'.format(username, e)) captcha_queue.put(account) await sleep(3) except ex.PgoapiError as e: print('pgoapi error on {}: {}'.format(username, e)) captcha_queue.put(account) await sleep(3) except Exception: captcha_queue.put(account) raise finally: try: driver.close() Session.close() except Exception: pass
async def main(): try: class AccountManager(BaseManager): pass AccountManager.register('captcha_queue') AccountManager.register('extra_queue') AccountManager.register('lv30_captcha_queue') AccountManager.register('lv30_account_queue') manager = AccountManager(address=get_address(), authkey=conf.AUTHKEY) manager.connect() captcha_queue = manager.captcha_queue() extra_queue = manager.extra_queue() lv30_captcha_queue = manager.lv30_captcha_queue() lv30_account_queue = manager.lv30_account_queue() def put_account_queue(account): if account.get('level', 0) < 30: extra_queue.put(account) else: lv30_account_queue.put(account) def put_captcha_queue(account): if account.get('leve', 0) < 30: captcha_queue.put(account) else: lv30_captcha_queue.put(account) if conf.GO_HASH: hashkey = conf.GO_HASH_KEY else: hashkey = conf.HASH_KEY activate_hash_server(hashkey, go_hash=conf.GO_HASH, hash_endpoint=conf.HASH_ENDPOINT, gohash_endpoint=conf.GOHASH_ENDPOINT) driver = webdriver.Chrome() driver.set_window_size(803, 807) while not captcha_queue.empty() or not lv30_captcha_queue.empty(): try: account = captcha_queue.get() except Empty: try: account = lv30_captcha_queue.get() except Empty: break username = account.get('username') location = account.get('location') if location and location != (0,0,0): lat = location[0] lon = location[1] else: lat, lon = randomize_point(center, 0.0001) try: alt = altitudes.get((lat, lon)) except KeyError: alt = await altitudes.fetch((lat, lon)) try: device_info = get_device_info(account) api = PGoApi(device_info=device_info) api.set_position(lat, lon, alt) authenticated = False try: if account['provider'] == 'ptc': api.auth_provider = AuthPtc() api.auth_provider._access_token = account['auth'] api.auth_provider._access_token_expiry = account['expiry'] if api.auth_provider.check_access_token(): api.auth_provider.authenticated = True authenticated = True except KeyError: pass if not authenticated: await api.set_authentication(username=username, password=account['password'], provider=account.get('provider', 'ptc')) request = api.create_request() await request.call() await sleep(.6) request.download_remote_config_version(platform=1, app_version=9100) request.check_challenge() request.get_hatched_eggs() request.get_inventory(last_timestamp_ms=account.get('inventory_timestamp', 0)) request.check_awarded_badges() request.download_settings() responses = await request.call() account['time'] = time() challenge_url = responses['CHECK_CHALLENGE'].challenge_url timestamp = responses['GET_INVENTORY'].inventory_delta.new_timestamp_ms account['location'] = lat, lon account['inventory_timestamp'] = timestamp if challenge_url == ' ': account['captcha'] = False print('No CAPTCHA was pending on {}.'.format(username)) put_account_queue(account) else: print('Trying to solve {}.'.format(username)) if await solve_captcha(challenge_url, api, driver, timestamp): account['time'] = time() account['captcha'] = False print('Solved CAPTCHA for {}, putting back in rotation.'.format(username)) put_account_queue(account) else: account['time'] = time() print('Failed to solve for {}'.format(username)) put_captcha_queue(account) except KeyboardInterrupt: put_captcha_queue(account) break except KeyError: print('Unexpected or empty response for {}, putting back on queue.'.format(username)) put_captcha_queue(account) try: print(response) except Exception: pass await sleep(3) except (ex.AuthException, ex.AuthTokenExpiredException) as e: print('Authentication error on {}: {}'.format(username, e)) put_captcha_queue(account) await sleep(3) except ex.AiopogoError as e: print('aiopogo error on {}: {}'.format(username, e)) put_captcha_queue(account) await sleep(3) except Exception: put_captcha_queue(account) raise finally: try: driver.close() close_sessions() except Exception: pass
async def main(): try: class AccountManager(BaseManager): pass AccountManager.register('captcha_queue') AccountManager.register('extra_queue') manager = AccountManager(address=get_address(), authkey=conf.AUTHKEY) manager.connect() captcha_queue = manager.captcha_queue() extra_queue = manager.extra_queue() activate_hash_server(conf.HASH_KEY) driver = webdriver.Chrome() driver.set_window_size(803, 807) while not captcha_queue.empty(): account = captcha_queue.get() username = account.get('username') location = account.get('location') if location and location != (0,0,0): lat = location[0] lon = location[1] else: lat, lon = randomize_point(center, 0.0001) try: alt = altitudes.get(point) except KeyError: alt = await altitudes.fetch(point) try: device_info = get_device_info(account) api = PGoApi(device_info=device_info) api.set_position(lat, lon, alt) authenticated = False try: if account['provider'] == 'ptc': api.auth_provider = AuthPtc() api.auth_provider._access_token = account['auth'] api.auth_provider._access_token_expiry = account['expiry'] if api.auth_provider.check_access_token(): api.auth_provider.authenticated = True authenticated = True except KeyError: pass if not authenticated: await api.set_authentication(username=username, password=account['password'], provider=account.get('provider', 'ptc')) request = api.create_request() await request.call() await sleep(.6) request.download_remote_config_version(platform=1, app_version=6100) request.check_challenge() request.get_hatched_eggs() request.get_inventory() request.check_awarded_badges() request.download_settings() response = await request.call() account['time'] = time() responses = response['responses'] challenge_url = responses['CHECK_CHALLENGE']['challenge_url'] timestamp = responses.get('GET_INVENTORY', {}).get('inventory_delta', {}).get('new_timestamp_ms') account['location'] = lat, lon, alt account['inventory_timestamp'] = timestamp if challenge_url == ' ': account['captcha'] = False print('No CAPTCHA was pending on {}.'.format(username)) extra_queue.put(account) else: if await solve_captcha(challenge_url, api, driver, timestamp): account['time'] = time() account['captcha'] = False print('Solved CAPTCHA for {}, putting back in rotation.'.format(username)) extra_queue.put(account) else: account['time'] = time() print('Failed to solve for {}'.format(username)) captcha_queue.put(account) except KeyboardInterrupt: captcha_queue.put(account) break except KeyError: print('Unexpected or empty response for {}, putting back on queue.'.format(username)) captcha_queue.put(account) try: print(response) except Exception: pass await sleep(3) except (ex.AuthException, ex.AuthTokenExpiredException) as e: print('Authentication error on {}: {}'.format(username, e)) captcha_queue.put(account) await sleep(3) except ex.AiopogoError as e: print('aiopogo error on {}: {}'.format(username, e)) captcha_queue.put(account) await sleep(3) except Exception: captcha_queue.put(account) raise finally: try: driver.close() close_sessions() except Exception: pass