def get_iv(): pokemon_id = request.args["pokemon_id"] pokemon_name = get_pokemon_name(pokemon_id) lat = request.args["latitude"] lng = request.args["longitude"] encounter_id = request.args.get("encounter_id") spawn_point_id = request.args.get("spawn_point_id") # Check cache cache_key = encounter_id if encounter_id else "{}-{}-{}".format( pokemon_id, lat, lng) result = get_cached_encounter(cache_key) if result: log.info( u"Returning cached result: {:.1f}% level {} {} with {} CP".format( result['iv_percent'], result['pokemon_level'], pokemon_name, result['cp'])) return jsonify(result) # Create a ScoutJob job = ScoutJob(pokemon_id, encounter_id, spawn_point_id, lat, lng) # Enqueue and wait for job to be processed jobs.put(job) while not job.processed: time.sleep(1) # Cache successful jobs and return result if job.result['success']: cache_encounter(cache_key, job.result) return jsonify(job.result)
def get_iv(): if not app_state.accept_new_requests: return reject('Not accepting new requests.') if not have_active_scouts(): return reject('No active scout available. All banned?') pokemon_id = request.args["pokemon_id"] pokemon_name = get_pokemon_name(pokemon_id) forced = request.args.get('forced') prio = PRIO_HIGH if forced is not None else get_pokemon_prio(pokemon_id) cache_enable = cfg_get('cache_timer') > 0 max_queued_jobs = cfg_get('max_queued_jobs') num_jobs = jobs.qsize() if max_queued_jobs and num_jobs >= max_queued_jobs and prio == PRIO_LOW: return reject( "Job queue full ({} items). Rejecting encounter with priority '{}'." .format(num_jobs, PRIO_NAMES[prio])) lat = request.args["latitude"] lng = request.args["longitude"] weather = request.args.get("weather", "unknown") encounter_id = normalize_encounter_id(request.args.get("encounter_id")) # Spawn point ID is assumed to be a hex string spawn_point_id = request.args.get("spawn_point_id") despawn_time = request.args.get("despawn_time") if cache_enable: # Check cache cache_key = "{}-{}".format( encounter_id, weather) if encounter_id else "{}-{}-{}".format( pokemon_id, lat, lng) result = get_cached_encounter(cache_key) if result: log.info( u"Returning cached result: {:.1f}% level {} {} with {} CP". format(result['iv_percent'], result['level'], pokemon_name, result['cp'])) return jsonify(result) # Create a ScoutJob job = ScoutJob(pokemon_id, encounter_id, spawn_point_id, lat, lng, despawn_time=despawn_time) # Enqueue and wait for job to be processed jobs.put((prio, time.time(), job)) while not job.processed: time.sleep(1) # Cache successful jobs and return result if cache_enable and job.result['success']: cache_encounter(cache_key, job.result) return jsonify(job.result)
def get_iv(): error = None if not app_state.accept_new_requests: error = 'Not accepting new requests.' if not have_active_scouts(): error = 'No active scout available. All banned?' max_queued_jobs = cfg_get('max_queued_jobs') num_jobs = jobs.qsize() if max_queued_jobs and num_jobs >= max_queued_jobs: error = "Job queue full ({} items). Perform less encounters or add more scouts.".format( num_jobs) if error: log.warning(error) return jsonify({'success': False, 'error': error}) pokemon_id = request.args["pokemon_id"] pokemon_name = get_pokemon_name(pokemon_id) lat = request.args["latitude"] lng = request.args["longitude"] weather = request.args.get("weather", "unknown") encounter_id = normalize_encounter_id(request.args.get("encounter_id")) # Spawn point ID is assumed to be a hex string spawn_point_id = request.args.get("spawn_point_id") despawn_time = request.args.get("despawn_time") # Check cache cache_key = "{}-{}".format(encounter_id, weather) if encounter_id else "{}-{}-{}".format( pokemon_id, lat, lng) result = get_cached_encounter(cache_key) if result: log.info( u"Returning cached result: {:.1f}% level {} {} with {} CP".format( result['iv_percent'], result['level'], pokemon_name, result['cp'])) return jsonify(result) # Create a ScoutJob job = ScoutJob(pokemon_id, encounter_id, spawn_point_id, lat, lng, despawn_time=despawn_time) # Enqueue and wait for job to be processed jobs.put(job) while not job.processed: time.sleep(1) # Cache successful jobs and return result if job.result['success']: cache_encounter(cache_key, job.result) return jsonify(job.result)
def get_iv(): if not app_state.accept_new_requests: return jsonify({ 'success': False, 'error': 'Not accepting new requests.' }) pokemon_id = request.args["pokemon_id"] pokemon_name = get_pokemon_name(pokemon_id) lat = request.args["latitude"] lng = request.args["longitude"] encounter_id = normalize_encounter_id(request.args.get("encounter_id")) # Spawn point ID is assumed to be a hex string spawn_point_id = request.args.get("spawn_point_id") # Check cache cache_key = encounter_id if encounter_id else "{}-{}-{}".format( pokemon_id, lat, lng) result = get_cached_encounter(cache_key) if result: log.info( u"Returning cached result: {:.1f}% level {} {} with {} CP".format( result['iv_percent'], result['level'], pokemon_name, result['cp'])) return jsonify(result) # Create a ScoutJob job = ScoutJob(pokemon_id, encounter_id, spawn_point_id, lat, lng) # Enqueue and wait for job to be processed jobs.put(job) while not job.processed: time.sleep(1) # Cache successful jobs and return result if job.result['success']: cache_encounter(cache_key, job.result) return jsonify(job.result)
def get_iv(): if not app_state.accept_new_requests: return jsonify({ 'success': False, 'error': 'Not accepting new requests.' }) payload = {} payload['encounter_id'] = normalized['encounter_id'] payload['pokemon_id'] = normalized['pokemon_id'] payload['latitude'] = normalized['lat'] payload['longitude'] = normalized['lon'] payload[ 'error'] = "PGSCOUT ONTVANGEN, PGSCOUT ACCEPTEERT GEEN NIEUWE REQUESTS" response = requests.post('http://192.168.1.101:1418/test6', json=payload) #return_iv(request.args) payload = {} payload['encounter_id'] = request.args["encounter_id"] payload['pokemon_id'] = request.args["pokemon_id"] payload['latitude'] = request.args["latitude"] payload['longitude'] = request.args["longitude"] payload['pokehunt_id'] = request.args['pokehunt_id'] #response = requests.post('http://192.168.1.101:1418/test3', json=payload) pokemon_id = request.args["pokemon_id"] pokemon_name = get_pokemon_name(pokemon_id) lat = request.args["latitude"] lng = request.args["longitude"] encounter_id = normalize_encounter_id(request.args.get("encounter_id")) spawn_point_id = normalize_spawn_point_id( request.args.get("spawn_point_id")) pokehunt_id = request.args["pokehunt_id"] # Check cache cache_key = encounter_id if encounter_id else "{}-{}-{}".format( pokemon_id, lat, lng) result = get_cached_encounter(cache_key) if result: log.info( u"Returning cached result: {:.1f}% level {} {} with {} CP".format( result['iv_percent'], result['level'], pokemon_name, result['cp'])) response = requests.post(cfg_get('customwebhook'), json=job.result) if (response.status_code != 200): log.error("Error sending webhook: {}".format( response.raise_for_status())) return jsonify({ 'success': False, 'error': 'Not accepting new requests.' }) else: return jsonify({'success': True}) # Create a ScoutJob job = ScoutJob(pokemon_id, encounter_id, spawn_point_id, lat, lng, pokehunt_id) jobs.put(job) # Enqueue and wait for job to be processed NO return jsonify({ 'success': True, })