def pgpool_load_accounts(num): request = { 'system_id': get_pgpool_system_id(), 'count': num, 'min_level': cfg_get('pgpool_min_level'), 'max_level': cfg_get('pgpool_max_level'), 'banned_or_new': True } while True: try: r = requests.get("{}/account/request".format( cfg_get('pgpool_url')), params=request) if r.status_code == 200: acc_json = r.json() if isinstance(acc_json, dict): acc_json = [acc_json] return acc_json else: log.error( "Could not request accounts from PGPool. Status {}: {} - Retrying...", r.status_code, repr(r.content)) except Exception as e: log.error( "Error requesting accounts from PGPool: {} - Retrying...", repr(e)) time.sleep(2)
def load_accounts_file(): accounts = [] log.info("Loading accounts from file {}.".format(cfg_get('accounts_file'))) with codecs.open(cfg_get('accounts_file'), mode='r', encoding='utf-8') as f: for line in f: if line.strip() == "": continue fields = line.split(",") if len(fields) == 3: auth = fields[0].strip() usr = fields[1].strip() pwd = fields[2].strip() elif len(fields) == 2: auth = 'ptc' usr = fields[0].strip() pwd = fields[1].strip() elif len(fields) == 1: fields = line.split(":") auth = 'ptc' usr = fields[0].strip() pwd = fields[1].strip() accounts.append({ 'auth_service': auth, 'username': usr, 'password': pwd }) if len(accounts) == 0: log.error("Could not load any accounts. Nothing to do. Exiting.") sys.exit(1) return accounts
def load_accounts_file(): accounts = [] log.info("Loading accounts from file {}.".format(cfg_get('accounts_file'))) with open(cfg_get('accounts_file'), 'r') as f: for num, line in enumerate(f, 1): if str.strip(line) == "": continue fields = line.split(",") if len(fields) == 3: auth = str.strip(fields[0]) usr = str.strip(fields[1]) pwd = str.strip(fields[2]) elif len(fields) == 2: auth = 'ptc' usr = str.strip(fields[0]) pwd = str.strip(fields[1]) elif len(fields) == 1: fields = line.split(":") auth = 'ptc' usr = str.strip(fields[0]) pwd = str.strip(fields[1]) accounts.append({ 'auth_service': auth, 'username': usr, 'password': pwd }) if len(accounts) == 0: log.error("Could not load any accounts. Nothing to do. Exiting.") sys.exit(1) return accounts
def check_thread(account_provider): while True: acc = account_provider.next() if acc: check_account( SingleLocationScanner(acc['auth_service'], acc['username'], acc['password'], cfg_get('latitude'), cfg_get('longitude'), cfg_get('hash_key_provider'), get_new_proxy())) else: break
def check_account(acc): try: try: response = acc.scan_once() lvl = acc.get_stats('level') if response: spin_below_level = cfg_get("spin_below_level") max_spins = cfg_get("max_spins") if lvl < spin_below_level: step_location = (acc.latitude, acc.longitude) stops = get_spinnable_pokestops(response, step_location) acc.log_info( "Account is level {}. Trying to spin {} Pokestop(s) for XP." .format(lvl, min(max_spins, len(stops)))) spins = 0 for stop in stops: if spin_pokestop(acc, stop, step_location): spins += 1 if spins >= max_spins: break else: acc.log_info( "Account already reached level {}. Not spinning any Pokestop." .format(spin_below_level)) except Exception as e: log.exception("Error checking account {}: {}".format( acc.username, repr(e))) try: if acc.seen_pokemon: if is_blind(acc): log.info("Account {} is shadowbanned. :-(".format( acc.username)) save_to_file(acc, 'blind') else: log.info("Account {} is good. :-)".format(acc.username)) save_to_file(acc, 'good') else: if acc.is_banned(): save_to_file(acc, 'banned') elif acc.has_captcha(): save_to_file(acc, 'captcha') else: save_to_file(acc, 'error') save_account_info(acc) except Exception as e: log.exception("Error saving checked account {} to file: {}".format( acc.username, repr(e))) finally: acc.release(reason="Checked with PGNumbra") del acc
def check_thread(account_provider): while True: acc = account_provider.next() if acc: check_account( SingleLocationScanner(acc['auth_service'], acc['username'], acc['password'], cfg_get('latitude'), cfg_get('longitude'), cfg_get('hash_key_provider'), get_new_proxy())) if cfg_get('max_good') and acc_stats['good'] >= cfg_get('max_good'): if acc_stats['good'] == cfg_get('max_good'): log.info("Found {} GOOD accounts. Exiting.".format(acc_stats['good'])) break; else: break
def next(self): self.lck.acquire() acc = None try: if not self.done: accounts = pgpool_load_accounts(1) if not accounts: log.warning("Got no further account back from PGPool.") self.finish() else: acc = accounts[0] log.debug("Loaded account #{} ({}) from PGPool".format( self.num_provided, acc['username'])) if not (acc['username'] in self.provided_accounts): self.provided_accounts.append(acc['username']) else: log.info( "Loaded previously checked account. Round trip done." ) self.release(acc['username']) acc = None self.finish() if acc: self.num_provided += 1 if self.num_provided >= cfg_get('pgpool_num_accounts'): self.finish() return acc finally: self.lck.release()
def count_pokemon(self, response): self.seen_pokemon = {} cells = response['GET_MAP_OBJECTS'].map_cells for cell in cells: for p in cell.wild_pokemons: pid = p.pokemon_data.pokemon_id self.seen_pokemon[pid] = self.seen_pokemon.get(pid, 0) + 1 if cfg_get('include_nearby'): for p in cell.nearby_pokemons: pid = p.pokemon_id self.seen_pokemon[pid] = self.seen_pokemon.get(pid, 0) + 1
def get_pokemon_name(pokemon_id): fmt = cfg_get('pokemon_format') if fmt == 'id': return "{:3}".format(pokemon_id) if not hasattr(get_pokemon_name, 'pokemon'): file_path = os.path.join('pokemon.json') with open(file_path, 'r') as f: get_pokemon_name.pokemon = json.loads(f.read()) name = get_pokemon_name.pokemon[str(pokemon_id)] return shorten(name) if fmt == 'short' else name
def pgpool_load_accounts(num): request = { 'system_id': get_pgpool_system_id(), 'count': num, 'banned_or_new': True } r = requests.get("{}/account/request".format(cfg_get('pgpool_url')), params=request) acc_json = r.json() if isinstance(acc_json, dict): acc_json = [acc_json] return acc_json
def scan_location(self): tries = 0 max_tries = cfg_get("scan_retries") while tries < max_tries: tries += 1 self.log_info("Scanning {}, {} (try #{})".format( self.latitude, self.longitude, tries)) try: responses = self.req_get_map_objects() self.count_pokemon(responses) if self.seen_pokemon: self.log_info("Successfully scanned location") return else: self.log_warning("Emtpy scan (try #{})".format(tries)) except Exception as e: self.log_error("Error on get_map_objects (try #{}): {}".format( tries, repr(e))) self.log_error("Failed {} times. Giving up.".format(max_tries))
def get_num_accounts(self): return cfg_get('pgpool_num_accounts')
log.info("PGNumbra ShadowCheck starting up.") # Delete result files. remove_account_file('good') remove_account_file('blind') remove_account_file('captcha') remove_account_file('banned') remove_account_file('error') if os.path.isfile(ACC_INFO_FILE): os.remove(ACC_INFO_FILE) init_proxies() if cfg_get('accounts_file'): account_provider = CSVAccProvider() elif cfg_get('pgpool_url') and cfg_get('pgpool_num_accounts') > 0: account_provider = PGPoolAccProvider() else: log.error( "No idea which accounts you want to check. Use either --accounts-file or --pgpool-url with --pgpool-num-accounts." ) sys.exit() init_account_info_file() num_threads = cfg_get('threads') log.info("Checking {} accounts with {} threads.".format( account_provider.get_num_accounts(), num_threads)) for i in range(0, num_threads):
log.error("Uncaught exception", exc_info=( exc_type, exc_value, exc_traceback)) # =========================================================================== log.info("PGNumbra ShadowCheck starting up.") install_thread_excepthook() sys.excepthook = handle_exception init_mr_mime(user_cfg={ 'pgpool_auto_update': False }) lat = cfg_get('latitude') lng = cfg_get('longitude') # Delete result files. remove_account_file('good') remove_account_file('blind') remove_account_file('captcha') remove_account_file('banned') remove_account_file('error') if os.path.isfile(ACC_INFO_FILE): os.remove(ACC_INFO_FILE) init_proxies() # This test must include nearby Pokemon to work properly.
'%(asctime)s [%(threadName)16s][%(module)14s][%(levelname)8s] %(message)s') log = logging.getLogger(__name__) # Silence some loggers logging.getLogger('pgoapi').setLevel(logging.WARNING) scanners = [] # =========================================================================== log.info("PGNumbra CompareScans starting up.") cfg_init() lat = cfg_get('latitude') lng = cfg_get('longitude') if not cfg_get('accounts_file'): log.error("Comparing accounts only works with --accounts-file.") sys.exit(1) init_proxies() accounts = load_accounts_file() for acc in accounts: t = Thread(target=acc.run) t.daemon = True t.start()
def load_accounts(): accounts = [] if cfg_get('accounts_file'): log.info("Loading accounts from file {}.".format( cfg_get('accounts_file'))) with open(cfg_get('accounts_file'), 'r') as f: for num, line in enumerate(f, 1): if str.strip(line) == "": continue fields = line.split(",") if len(fields) == 3: auth = str.strip(fields[0]) usr = str.strip(fields[1]) pwd = str.strip(fields[2]) elif len(fields) == 2: auth = 'ptc' usr = str.strip(fields[0]) pwd = str.strip(fields[1]) elif len(fields) == 1: fields = line.split(":") auth = 'ptc' usr = str.strip(fields[0]) pwd = str.strip(fields[1]) accounts.append( SingleLocationScanner(auth, usr, pwd, cfg_get('latitude'), cfg_get('longitude'), cfg_get('hash_key_provider'), get_new_proxy())) elif cfg_get('pgpool_url') and cfg_get('pgpool_num_accounts') > 0: log.info("Trying to load {} accounts from PGPool.".format( cfg_get('pgpool_num_accounts'))) request = { 'system_id': get_pgpool_system_id(), 'count': cfg_get('pgpool_num_accounts'), 'banned_or_new': True } r = requests.get("{}/account/request".format(cfg_get('pgpool_url')), params=request) acc_json = r.json() if isinstance(acc_json, dict): acc_json = [acc_json] if len(acc_json) > 0: log.info("Loaded {} accounts from PGPool.".format(len(acc_json))) for acc in acc_json: accounts.append( SingleLocationScanner(acc['auth_service'], acc['username'], acc['password'], cfg_get('latitude'), cfg_get('longitude'), cfg_get('hash_key_provider'), get_new_proxy())) if len(accounts) == 0: log.error("Could not load any accounts. Nothing to do. Exiting.") sys.exit(1) return accounts
'%(asctime)s [%(threadName)16s][%(module)14s][%(levelname)8s] %(message)s') log = logging.getLogger(__name__) # Silence some loggers logging.getLogger('pgoapi').setLevel(logging.WARNING) scanners = [] # =========================================================================== log.info("PGNumbra CompareScans starting up.") cfg_init() lat = cfg_get('latitude') lng = cfg_get('longitude') init_proxies() with open(cfg_get('accounts_file'), 'r') as f: for num, line in enumerate(f, 1): fields = line.split(",") fields = map(str.strip, fields) scanner = SingleLocationScanner(fields[0], fields[1], fields[2], lat, lng, cfg_get('hash_key'), get_new_proxy()) scanners.append(scanner) t = Thread(target=scanner.run) t.daemon = True t.start()
def release(self, username): url = '{}/account/release'.format(cfg_get('pgpool_url')) data = {'username': username} r = requests.post(url, data=json.dumps(data))
def finish(self): self.done = True log.info( "Finished providing accounts. Provided {} of {} accounts in total." .format(self.num_provided, cfg_get('pgpool_num_accounts')))
remove_account_file('good') remove_account_file('blind') remove_account_file('captcha') remove_account_file('banned') remove_account_file('error') if os.path.isfile(ACC_INFO_FILE): os.remove(ACC_INFO_FILE) init_proxies() accounts = load_accounts() init_account_info_file(accounts) num_threads = cfg_get('threads') log.info("Checking {} accounts with {} threads.".format( len(accounts), num_threads)) pool = ThreadPool(num_threads) pool.map_async(check_account, accounts).get(sys.maxint) pool.close() pool.join() log.info("All {} accounts processed.".format(len(accounts))) log_results('good') log_results('blind') log_results('captcha') log_results('banned') log_results('error') if acc_stats['good'] == 0 and acc_stats['blind'] > 0:
return None return acc.rareless_scans != 0 def log_results(key): if acc_stats[key]: log.info("{:7}: {}".format(key.upper(), acc_stats[key])) # =========================================================================== cfg_init(shadowcheck=True) log.info("PGNumbra ShadowCheck starting up.") lat = cfg_get('latitude') lng = cfg_get('longitude') # Delete result files. remove_account_file('good') remove_account_file('blind') remove_account_file('captcha') remove_account_file('banned') remove_account_file('error') if os.path.isfile(ACC_INFO_FILE): os.remove(ACC_INFO_FILE) init_proxies() accounts = load_accounts()
def check_proxies(): check_results = [0] * (check_result_max + 1) # Load proxies from the file if such a file is configured. proxies_file = cfg_get('proxies_file') if not proxies_file: return [] log.info('Loading proxies from file {}.'.format(proxies_file)) source_proxies = [] try: with open(proxies_file) as f: for line in f: # Ignore blank lines and comment lines. if len(line.strip()) == 0 or line.startswith('#'): continue source_proxies.append(line.strip()) except IOError: log.error('Could not load proxies from {}.'.format(proxies_file)) return [] log.info('Loaded {} proxies.'.format(len(source_proxies))) if len(source_proxies) == 0: log.error('Proxy file {} was configured but ' + 'no proxies were loaded. Aborting.'.format(proxies_file)) sys.exit(1) proxy_queue = Queue() total_proxies = len(source_proxies) log.info('Checking proxies...') working_proxies = [] for proxy in enumerate(source_proxies): proxy_queue.put(proxy) t = Thread(target=check_proxy, name='check_proxy', args=(proxy_queue, 5, working_proxies, check_results)) t.daemon = True t.start() # This is painful but we need to wait here until proxy_queue is # completed so we have a working list of proxies. proxy_queue.join() num_working_proxies = len(working_proxies) if num_working_proxies == 0: log.error('Proxies were configured but no working ' + 'proxies were found. Aborting.') sys.exit(1) else: other_fails = (check_results[check_result_failed] + check_results[check_result_wrong] + check_results[check_result_exception] + check_results[check_result_empty]) log.info( 'Proxy check completed. Working: %d, banned: %d, ' + 'timeout: %d, other fails: %d of total %d configured.', num_working_proxies, check_results[check_result_banned], check_results[check_result_timeout], other_fails, total_proxies) return working_proxies
'%(asctime)s [%(threadName)16s][%(module)14s][%(levelname)8s] %(message)s') log = logging.getLogger(__name__) # Silence some loggers logging.getLogger('pgoapi').setLevel(logging.WARNING) scanners = [] # =========================================================================== log.info("PGNumbra CompareScans starting up.") cfg_init() lat = cfg_get('latitude') lng = cfg_get('longitude') init_proxies() accounts = load_accounts() for acc in accounts: t = Thread(target=acc.run) t.daemon = True t.start() # Start thread to print current status and get user input. t = Thread(target=print_status, name='status_printer', args=(accounts, )) t.daemon = True t.start()