Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
    def __init__(self, pokemon_id, encounter_id, spawn_point_id, lat, lng):
        self.pokemon_id = int(pokemon_id)
        self.pokemon_name = get_pokemon_name(pokemon_id)
        self.encounter_id = encounter_id
        self.spawn_point_id = spawn_point_id
        self.lat = float(lat)
        self.lng = float(lng)
        self.processed = False
        self.result = {}

        # Use fixed random altitude per job
        self.altitude = random.randint(12, 108)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
    def __init__(self,
                 pokemon_id,
                 encounter_id,
                 spawn_point_id,
                 lat,
                 lng,
                 despawn_time=None):
        self.pokemon_id = int(pokemon_id)
        self.pokemon_name = get_pokemon_name(pokemon_id)
        self.encounter_id = encounter_id
        self.spawn_point_id = spawn_point_id
        self.lat = float(lat)
        self.lng = float(lng)
        self.despawn_time = despawn_time

        self.processed = False
        self.result = {}

        # Set a time when this job expires if a TTL was given
        ttl = cfg_get('max_job_ttl')
        self.expire_at = time.time() + (ttl * 60) if ttl else None

        # Use fixed random altitude per job
        self.altitude = random.randint(12, 108)
Exemplo n.º 6
0
 def format_pstat_line(current_line, e):
     return line_tmpl.format(get_pokemon_name(e['pid']), e['count'])
Exemplo n.º 7
0
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,
    })
Exemplo n.º 8
0
 def format_pstat_line(current_line, e):
     return line_tmpl.format(get_pokemon_name(e['pid']), e['count'])