# Control the search status (running or not) across threads pause_bit = Event() pause_bit.clear() # Setup the location tracking queue and push the first location on new_location_queue = Queue() new_location_queue.put(position) if not args.only_server: # Gather the pokemons! if not args.mock: log.debug('Starting a real search thread') search_thread = Thread(target=search_overseer_thread, args=(args, new_location_queue, pause_bit)) else: log.debug('Starting a fake search thread') insert_mock_data(position) search_thread = Thread(target=fake_search_loop) search_thread.daemon = True search_thread.name = 'search_thread' search_thread.start() if args.cors: CORS(app); app.set_search_control(pause_bit) app.set_location_queue(new_location_queue) config['ROOT_PATH'] = app.root_path config['GMAPS_KEY'] = args.gmaps_key config['REQ_SLEEP'] = args.scan_delay
log.info('Parsing of Pokemon disabled.') if args.no_pokestops: log.info('Parsing of Pokestops disabled.') if args.no_gyms: log.info('Parsing of Gyms disabled.') config['ORIGINAL_LATITUDE'] = position[0] config['ORIGINAL_LONGITUDE'] = position[1] config['LOCALE'] = args.locale config['CHINA'] = args.china if not args.only_server: if not args.mock: start_locator_thread(args) else: insert_mock_data() app = Pogom(__name__) if args.cors: CORS(app); config['ROOT_PATH'] = app.root_path if args.gmaps_key is not None: config['GMAPS_KEY'] = args.gmaps_key else: config['GMAPS_KEY'] = load_credentials(os.path.dirname(os.path.realpath(__file__)))['gmaps_key'] if args.no_server: while not search_thread.isAlive(): time.sleep(1)
# Control the search status (running or not) across threads pause_bit = Event() pause_bit.clear() # Setup the location tracking queue and push the first location on new_location_queue = Queue() new_location_queue.put(position) if not args.only_server: # Gather the pokemons! if not args.mock: log.debug('Starting a real search thread') search_thread = Thread(target=search_overseer_thread, args=(args, new_location_queue, pause_bit, encryption_lib_path)) else: log.debug('Starting a fake search thread') insert_mock_data(position) search_thread = Thread(target=fake_search_loop) search_thread.daemon = True search_thread.name = 'search_thread' search_thread.start() if args.cors: CORS(app) # No more stale JS init_cache_busting(app) app.set_search_control(pause_bit) app.set_location_queue(new_location_queue)
config['ORIGINAL_LATITUDE'] = position[0] config['ORIGINAL_LONGITUDE'] = position[1] config['LOCALE'] = args.locale config['CHINA'] = args.china if not args.only_server: # Gather the pokemons! if not args.mock: log.debug( 'Starting a real search thread and {} search runner thread(s)'. format(args.num_threads)) create_search_threads(args.num_threads) search_thread = Thread(target=search_loop, args=(args, )) else: log.debug('Starting a fake search thread') insert_mock_data() search_thread = Thread(target=fake_search_loop) search_thread.daemon = True search_thread.name = 'search_thread' search_thread.start() app = Pogom(__name__) if args.cors: CORS(app) config['ROOT_PATH'] = app.root_path config['GMAPS_KEY'] = args.gmaps_key config['REQ_SLEEP'] = args.scan_delay
logging.getLogger("requests").setLevel(logging.DEBUG) logging.getLogger("pgoapi").setLevel(logging.DEBUG) logging.getLogger("rpc_api").setLevel(logging.DEBUG) create_tables() position = get_pos_by_name(args.location) log.info('Parsed location is: {:.4f}/{:.4f}/{:.4f} (lat/lng/alt)'. format(*position)) config['ORIGINAL_LATITUDE'] = position[0] config['ORIGINAL_LONGITUDE'] = position[1] if args.ignore: Pokemon.IGNORE = [i.lower().strip() for i in args.ignore.split(',')] elif args.only: Pokemon.ONLY = [i.lower().strip() for i in args.only.split(',')] if not args.mock: start_locator_thread(args) else: insert_mock_data(args.location, 6) app = Pogom(__name__) config['ROOT_PATH'] = app.root_path if args.gmaps_key is not None: config['GMAPS_KEY'] = args.gmaps_key else: config['GMAPS_KEY'] = load_credentials(os.path.dirname(os.path.realpath(__file__)))['gmaps_key'] app.run(threaded=True, debug=args.debug, host=args.host, port=args.port)
def main(): # Check if we have the proper encryption library file and get its path encryption_lib_path = get_encryption_lib_path() if encryption_lib_path is "": sys.exit(1) args = get_args() if args.debug: log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) # These are very noisey, let's shush them up a bit logging.getLogger('peewee').setLevel(logging.INFO) logging.getLogger('requests').setLevel(logging.WARNING) logging.getLogger('pgoapi.pgoapi').setLevel(logging.WARNING) logging.getLogger('pgoapi.rpc_api').setLevel(logging.INFO) logging.getLogger('werkzeug').setLevel(logging.ERROR) config['parse_pokemon'] = not args.no_pokemon config['parse_pokestops'] = not args.no_pokestops config['parse_gyms'] = not args.no_gyms # Turn these back up if debugging if args.debug: logging.getLogger('requests').setLevel(logging.DEBUG) logging.getLogger('pgoapi').setLevel(logging.DEBUG) logging.getLogger('rpc_api').setLevel(logging.DEBUG) # use lat/lng directly if matches such a pattern prog = re.compile("^(\-?\d+\.\d+),?\s?(\-?\d+\.\d+)$") res = prog.match(args.location) if res: log.debug('Using coordinates from CLI directly') position = (float(res.group(1)), float(res.group(2)), 0) else: log.debug('Looking up coordinates in API') position = util.get_pos_by_name(args.location) if not any(position): log.error('Could not get a position by name, aborting') sys.exit() log.info('Parsed location is: %.4f/%.4f/%.4f (lat/lng/alt)', position[0], position[1], position[2]) if args.no_pokemon: log.info('Parsing of Pokemon disabled') if args.no_pokestops: log.info('Parsing of Pokestops disabled') if args.no_gyms: log.info('Parsing of Gyms disabled') config['LOCALE'] = args.locale config['CHINA'] = args.china app = Pogom(__name__) db = init_database(app) if args.clear_db: log.info('Clearing database') if args.db_type == 'mysql': drop_tables(db) elif os.path.isfile(args.db): os.remove(args.db) create_tables(db) app.set_current_location(position) # Control the search status (running or not) across threads pause_bit = Event() pause_bit.clear() # Setup the location tracking queue and push the first location on new_location_queue = Queue() new_location_queue.put(position) if not args.only_server: # Gather the pokemons! if not args.mock: # check the sort of scan if not args.spawnpoint_scanning: log.debug('Starting a real search thread') search_thread = Thread(target=search_overseer_thread, args=(args, new_location_queue, pause_bit, encryption_lib_path)) # using -ss else: if args.dump_spawnpoints: with open(args.spawnpoint_scanning, 'w+') as file: log.info('exporting spawns') spawns = Pokemon.get_spawnpoints_in_hex(position, args.step_limit) file.write(json.dumps(spawns)) file.close() log.info('Finished exporting spawns') # start the scan sceduler search_thread = Thread(target=search_overseer_thread_ss, args=(args, new_location_queue, pause_bit, encryption_lib_path)) else: log.debug('Starting a fake search thread') insert_mock_data(position) search_thread = Thread(target=fake_search_loop) search_thread.daemon = True search_thread.name = 'search_thread' search_thread.start() if args.cors: CORS(app) # No more stale JS init_cache_busting(app) app.set_search_control(pause_bit) app.set_location_queue(new_location_queue) config['ROOT_PATH'] = app.root_path config['GMAPS_KEY'] = args.gmaps_key if args.no_server: # This loop allows for ctrl-c interupts to work since flask won't be holding the program open while search_thread.is_alive(): time.sleep(60) else: ssl_context = None if args.ssl_certificate and args.ssl_privatekey \ and os.path.exists(args.ssl_certificate) and os.path.exists(args.ssl_privatekey): ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) ssl_context.load_cert_chain(args.ssl_certificate, args.ssl_privatekey) log.info('Web server in SSL mode.') app.run(threaded=True, use_reloader=False, debug=args.debug, host=args.host, port=args.port, ssl_context=ssl_context)
def start_locator_thread(args): search_thread = Thread(target=search_loop, args=(args,)) search_thread.daemon = True search_thread.name = 'search_thread' search_thread.start() if __name__ == '__main__': logging.basicConfig(level=logging.INFO, format='%(asctime)s [%(module)11s] [%(levelname)7s] %(message)s') logging.getLogger("peewee").setLevel(logging.INFO) logging.getLogger("requests").setLevel(logging.WARNING) logging.getLogger("pogom.pgoapi.pgoapi").setLevel(logging.INFO) logging.getLogger("pogom.pgoapi.rpc_api").setLevel(logging.CRITICAL) args = get_args() create_tables() set_location(args.location, args.radius) set_cover() if not args.mock: start_locator_thread(args) else: insert_mock_data(config, 6) app = Pogom(__name__) config['ROOT_PATH'] = app.root_path app.run(threaded=True, debug=args.debug, host=args.host, port=args.port)