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 = normalize_encounter_id(request.args.get("encounter_id")) spawn_point_id = normalize_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, })