Пример #1
0
def process_step(args, api_endpoint, access_token, profile_response,
                 pokemonsJSON, ignore, only):
    print('[+] Searching for Pokemon at location {} {}'.format(FLOAT_LAT, FLOAT_LONG))
    origin = LatLng.from_degrees(FLOAT_LAT, FLOAT_LONG)
    step_lat = FLOAT_LAT
    step_long = FLOAT_LONG
    parent = CellId.from_lat_lng(LatLng.from_degrees(FLOAT_LAT,
                                                     FLOAT_LONG)).parent(15)
    h = get_heartbeat(args.auth_service, api_endpoint, access_token,
                      profile_response)
    hs = [h]
    seen = set([])

    for child in parent.children():
        latlng = LatLng.from_point(Cell(child).get_center())
        set_location_coords(latlng.lat().degrees, latlng.lng().degrees, 0)
        hs.append(
            get_heartbeat(args.auth_service, api_endpoint, access_token,
                          profile_response))
    set_location_coords(step_lat, step_long, 0)
    visible = []

    for hh in hs:
        try:
            for cell in hh.cells:
                for wild in cell.WildPokemon:
                    hash = wild.SpawnPointId + ':' \
                        + str(wild.pokemon.PokemonId)
                    if hash not in seen:
                        visible.append(wild)
                        seen.add(hash)
                if cell.Fort:
                    for Fort in cell.Fort:
                        if Fort.Enabled == True:
                            if args.china:
                                (Fort.Latitude, Fort.Longitude) = \
transform_from_wgs_to_gcj(Location(Fort.Latitude, Fort.Longitude))
                            if Fort.GymPoints and args.display_gym:
                                gyms[Fort.FortId] = [Fort.Team, Fort.Latitude,
                                                     Fort.Longitude, Fort.GymPoints]

                            elif Fort.FortType \
                                and args.display_pokestop:
                                expire_time = 0
                                if Fort.LureInfo.LureExpiresTimestampMs:
                                    expire_time = datetime\
                                        .fromtimestamp(Fort.LureInfo.LureExpiresTimestampMs / 1000.0)\
                                        .strftime("%H:%M:%S")
                                if (expire_time != 0 or not args.onlylure):
                                    pokestops[Fort.FortId] = [Fort.Latitude,
                                                              Fort.Longitude, expire_time]
        except AttributeError:
            break

    for poke in visible:
        pokeid = str(poke.pokemon.PokemonId)
        pokename = pokemonsJSON[pokeid]
        if args.ignore:
            if pokename.lower() in ignore or pokeid in ignore:
                continue
        elif args.only:
            if pokename.lower() not in only and pokeid not in only:
                continue

        disappear_timestamp = time.time() + poke.TimeTillHiddenMs \
            / 1000

        if args.china:
            (poke.Latitude, poke.Longitude) = \
                transform_from_wgs_to_gcj(Location(poke.Latitude,
                    poke.Longitude))


        pokemon_obj = {
            "lat": poke.Latitude,
            "lng": poke.Longitude,
            "disappear_time": disappear_timestamp,
            "id": poke.pokemon.PokemonId,
            "name": pokename
        }

        pokemons[poke.SpawnPointId] = pokemon_obj

        notifier.pokemon_found(pokemon_obj)
Пример #2
0
import notifier
pokemon = { "lat": 38.95, "lng": 77.07, "name": "test", "disappear_time": 72016083512 }
notifier.pokemon_found( pokemon )
Пример #3
0
def process_step(args, api_endpoint, access_token, profile_response,
                 pokemonsJSON, ignore, only):
    print('[+] Searching for Pokemon at location {} {}'.format(
        FLOAT_LAT, FLOAT_LONG))
    origin = LatLng.from_degrees(FLOAT_LAT, FLOAT_LONG)
    step_lat = FLOAT_LAT
    step_long = FLOAT_LONG
    parent = CellId.from_lat_lng(LatLng.from_degrees(FLOAT_LAT,
                                                     FLOAT_LONG)).parent(15)
    h = get_heartbeat(args.auth_service, api_endpoint, access_token,
                      profile_response)
    hs = [h]
    seen = {}

    for child in parent.children():
        latlng = LatLng.from_point(Cell(child).get_center())
        set_location_coords(latlng.lat().degrees, latlng.lng().degrees, 0)
        hs.append(
            get_heartbeat(args.auth_service, api_endpoint, access_token,
                          profile_response))
    set_location_coords(step_lat, step_long, 0)
    visible = []

    for hh in hs:
        try:
            for cell in hh.cells:
                for wild in cell.WildPokemon:
                    hash = wild.SpawnPointId
                    if hash not in seen.keys() or (seen[hash].TimeTillHiddenMs
                                                   <= wild.TimeTillHiddenMs):
                        visible.append(wild)
                    seen[hash] = wild.TimeTillHiddenMs
                if cell.Fort:
                    for Fort in cell.Fort:
                        if Fort.Enabled == True:
                            if args.china:
                                (Fort.Latitude, Fort.Longitude) = \
transform_from_wgs_to_gcj(Location(Fort.Latitude, Fort.Longitude))
                            if Fort.GymPoints and args.display_gym:
                                gyms[Fort.FortId] = [
                                    Fort.Team, Fort.Latitude, Fort.Longitude,
                                    Fort.GymPoints
                                ]

                            elif Fort.FortType \
                                and args.display_pokestop:
                                expire_time = 0
                                if Fort.LureInfo.LureExpiresTimestampMs:
                                    expire_time = datetime\
                                        .fromtimestamp(Fort.LureInfo.LureExpiresTimestampMs / 1000.0)\
                                        .strftime("%H:%M:%S")
                                if (expire_time != 0 or not args.onlylure):
                                    pokestops[Fort.FortId] = [
                                        Fort.Latitude, Fort.Longitude,
                                        expire_time
                                    ]
        except AttributeError:
            # Reset login session if problems happen
            global login_session, global_token
            login_session = None
            global_token = None
            break

    for poke in visible:
        pokeid = str(poke.pokemon.PokemonId)
        pokename = pokemonsJSON[pokeid]
        if args.ignore:
            if pokename.lower() in ignore or pokeid in ignore:
                continue
        elif args.only:
            if pokename.lower() not in only and pokeid not in only:
                continue

        disappear_timestamp = time.time() + poke.TimeTillHiddenMs \
            / 1000

        if args.china:
            (poke.Latitude, poke.Longitude) = \
                transform_from_wgs_to_gcj(Location(poke.Latitude,
                    poke.Longitude))

        pokemon_obj = {
            "lat": poke.Latitude,
            "lng": poke.Longitude,
            "disappear_time": disappear_timestamp,
            "id": poke.pokemon.PokemonId,
            "name": pokename
        }

        #change
        print "Pokemon :", pokemon_obj
        if poke.SpawnPointId not in pokemons:
            pokemons[poke.SpawnPointId] = pokemon_obj

            notifier.pokemon_found(pokemon_obj)
Пример #4
0
            "lng": poke.Longitude,
            "disappear_time": disappear_timestamp,
            "id": poke.pokemon.PokemonId,
            "name": pokename
        }

<<<<<<< HEAD
        

        
		#change
	print "Pokemon :", pokemon_obj
        if poke.SpawnPointId not in pokemons:
             pokemons[poke.SpawnPointId] = pokemon_obj
		     
             notifier.pokemon_found(pokemon_obj)
        #change
		
=======
        pokemons[poke.SpawnPointId] = pokemon_obj

        print "Pokemon :", pokemon_obj

        if poke.SpawnPointId not in pokemons:
            notifier.pokemon_found(pokemon_obj)

>>>>>>> origin/master
def clear_stale_pokemons():
    current_time = time.time()

    for pokemon_key in pokemons.keys():
Пример #5
0
import notifier
pokemon = { "lat": 38.95, "lng": 77.07, "name": "Pidgey", "disappear_time": 72016083512 }
notifier.pokemon_found( pokemon )
Пример #6
0
def find_poi(api, start_lat, start_lng, step_limit, step_size, time_delta):
    config = init_config()
    poi = {'pokemons': {}, 'forts': []}

    
    coords = list(generate_location_steps([start_lat, start_lng], step_limit, step_size))
    
    # clean up array
    log.info("Cleaning up Pokemon-Array...")
    clean_array()
    push_map(pokemons, start_lat, start_lng, time_delta, step_limit, step_size)
    newp = False 
    
    step = 0
    for coord in coords:
        # lat = coord['lat']
        # lng = coord['lng']
        lat = coord[0]
        lng = coord[1]
        api.set_position(lat, lng, 0)
        
        step = step + 1
        failed_total = 0
        
        
        while True:

            # After so many attempts, let's get out of here
            if failed_total >= 10:
                # I am choosing to NOT place this item back in the queue
                # otherwise we could get a "bad scan" area and be stuck
                # on this overall loop forever. Better to lose one cell
                # than have the scanner, essentially, halt.
                log.error('Search step %d went over max scan_retires; abandoning', step)
                break

            # Increase sleep delay between each failed scan
            # By default scan_dela=5, scan_retries=5 so
            # We'd see timeouts of 5, 10, 15, 20, 25
            sleep_time = 5 * (1 + failed_total)

            # Ok, let's get started -- check our login status
          #  check_login(args, account, api, step_location)

            

            # Make the actual request (finally!)
            cell_ids = get_cell_ids(lat, lng)
            timestamps = [0,] * len(cell_ids)
            response_dict = api.get_map_objects(latitude = util.f2i(lat), longitude = util.f2i(lng), since_timestamp_ms = timestamps, cell_id = cell_ids)

            # G'damnit, nothing back. Mark it up, sleep, carry on
            if not response_dict:
                log.error('Search step %d area download failed, retrying request in %g seconds', step, sleep_time)
                failed_total += 1
                time.sleep(sleep_time)
                continue

               
            
            # Got the response, lock for parsing and do so (or fail, whatever)

            try:
            
                if (response_dict['responses']):
                    if 'status' in response_dict['responses']['GET_MAP_OBJECTS']:
                        if response_dict['responses']['GET_MAP_OBJECTS']['status'] == 1:
                            for map_cell in response_dict['responses']['GET_MAP_OBJECTS']['map_cells']:
                                
                                for p in map_cell.get('wild_pokemons', []):
                                    # time_till_hidden_ms was overflowing causing a negative integer. It was also returning a value above 3.6M ms.
                                    if (0 < p['time_till_hidden_ms'] < 3600000):
                                        d_t = ((p['last_modified_timestamp_ms'] + p['time_till_hidden_ms'])) / 1000
                                    else:
                                        # Set a value of 15 minutes because currently its unknown but larger than 15.
                                        d_t = ((p['last_modified_timestamp_ms'] + 900000)) / 1000

                                    if (p['encounter_id'] not in pokemons):
                                        printPokemon(p['pokemon_data']['pokemon_id'], p['latitude'], p['longitude'], d_t, time_delta)
                                        pokemons[p['encounter_id']] = {
                                            'encounter_id': b64encode(str(p['encounter_id'])),
                                            'spawnpoint_id': p['spawn_point_id'],
                                            'pokemon_id': p['pokemon_data']['pokemon_id'],
                                            'latitude': p['latitude'],
                                            'longitude': p['longitude'],
                                            'disappear_time': d_t,
                                            'pokename': pokemonsJSON[str(p['pokemon_data']['pokemon_id'])]
                                        }
                                        pokemon_found(pokemonsJSON[str(p['pokemon_data']['pokemon_id'])], p['latitude'], p['longitude'], d_t, time_delta)
                                        newp = True
                                        if config.mappath != None:
                                            push_map(pokemons, start_lat, start_lng, time_delta, step_limit, step_size)
                                            # clean up array
                                            log.info("Cleaning up Pokemon-Array...")
                                            clean_array()
                                    else:
                                        log.info("Found already known " + pokemonsJSON[str(p['pokemon_data']['pokemon_id'])] + "! No Notification.")

                log.debug('Search step %s completed', step)
               
                break  # All done, get out of the request-retry loop
            except KeyError:
                log.exception('Search step %s map parsing failed, retrying request in %g seconds.', step, sleep_time)
                failed_total += 1
                time.sleep(sleep_time)

        
        #get_cellid was buggy -> replaced through get_cell_ids from pokecli
        #timestamp gets computed a different way:



        time.sleep(1)
    # new dict, binary data
    # print('POI dictionary: \n\r{}'.format(json.dumps(poi, indent=2)))
    log.debug('=========================================')
    log.debug('Open this in a browser to see the path the spiral search took:')
    print_gmaps_dbug(coords)
    log.info('=========================================')
    log.info('Currently observed Pokemons:')
    if len(pokemons) == 0:
        log.info('None')
    for p in pokemons:
        log.info(str(p) + " " + pokemonsJSON[str(pokemons[p]['pokemon_id'])] + " " + str(datetime.fromtimestamp(pokemons[p]['disappear_time'] + time_delta)) + " " + str(pokemons[p]['latitude']) + "," + str(pokemons[p]['longitude']))
    log.info('=========================================')
Пример #7
0
def process_step(args, api_endpoint, access_token, profile_response,
                 pokemonsJSON, ignore, only, pokemons):
    print('[+] Searching for Pokemon at location {} {}'.format(FLOAT_LAT, FLOAT_LONG))
    origin = LatLng.from_degrees(FLOAT_LAT, FLOAT_LONG)
    step_lat = FLOAT_LAT
    step_long = FLOAT_LONG
    parent = CellId.from_lat_lng(LatLng.from_degrees(FLOAT_LAT,
                                                     FLOAT_LONG)).parent(15)
    h = get_heartbeat(args.auth_service, api_endpoint, access_token,
                      profile_response)
    hs = [h]
    seen = {}

    for child in parent.children():
        latlng = LatLng.from_point(Cell(child).get_center())
        set_location_coords(latlng.lat().degrees, latlng.lng().degrees, 0)
        hs.append(
            get_heartbeat(args.auth_service, api_endpoint, access_token,
                          profile_response))
    set_location_coords(step_lat, step_long, 0)
    visible = []

    for hh in hs:
        try:
            for cell in hh.cells:
                for wild in cell.WildPokemon:
                    hash = wild.SpawnPointId;
                    if hash not in seen.keys() or (seen[hash].TimeTillHiddenMs <= wild.TimeTillHiddenMs):
                        visible.append(wild)
                    seen[hash] = wild.TimeTillHiddenMs
        except AttributeError:
            break

    for poke in visible:
        pokeid = str(poke.pokemon.PokemonId)
        pokename = pokemonsJSON[pokeid]
        if args.ignore:
            if pokename.lower() in ignore or pokeid in ignore:
                continue
        elif args.only:
            if pokename.lower() not in only and pokeid not in only:
                continue

        disappear_timestamp = time.time() + poke.TimeTillHiddenMs \
            / 1000

        if args.china:
            (poke.Latitude, poke.Longitude) = \
                transform_from_wgs_to_gcj(Location(poke.Latitude,
                    poke.Longitude))

        pokemon_obj = {
            "lat": poke.Latitude,
            "lng": poke.Longitude,
            "disappear_time": disappear_timestamp,
            "id": poke.pokemon.PokemonId,
            "name": pokename
        }

        if not pokemons.exists(poke.SpawnPointId):
            notifier.pokemon_found(pokemon_obj)
            expires = (datetime.fromtimestamp(disappear_timestamp) - datetime.now()).seconds

            print 'expires in {} seconds'.format(expires)

            if expires > 0:
                pokemons.setex(poke.SpawnPointId, json.dumps(pokemon_obj), expires)

        print "Pokemon :", pokemon_obj
        print "PokespawnpointId: {}".format(poke.SpawnPointId)
Пример #8
0
def process_step(args, api_endpoint, access_token, profile_response,
                 pokemonsJSON, ignore, only):
    print('[+] Searching for Pokemon at location {} {}'.format(FLOAT_LAT, FLOAT_LONG))
    origin = LatLng.from_degrees(FLOAT_LAT, FLOAT_LONG)
    step_lat = FLOAT_LAT
    step_long = FLOAT_LONG
    parent = CellId.from_lat_lng(LatLng.from_degrees(FLOAT_LAT,
                                                     FLOAT_LONG)).parent(15)
    h = get_heartbeat(args.auth_service, api_endpoint, access_token,
                      profile_response)
    hs = [h]
    seen = {}

    for child in parent.children():
        latlng = LatLng.from_point(Cell(child).get_center())
        set_location_coords(latlng.lat().degrees, latlng.lng().degrees, 0)
        hs.append(
            get_heartbeat(args.auth_service, api_endpoint, access_token,
                          profile_response))
    set_location_coords(step_lat, step_long, 0)
    visible = []

    for hh in hs:
        try:
            for cell in hh.cells:
                for wild in cell.WildPokemon:
                    hash = wild.SpawnPointId;
                    if hash not in seen.keys() or (seen[hash].TimeTillHiddenMs <= wild.TimeTillHiddenMs):
                        visible.append(wild)
                    seen[hash] = wild.TimeTillHiddenMs
                if cell.Fort:
                    for Fort in cell.Fort:
                        if Fort.Enabled == True:
                            if args.china:
                                (Fort.Latitude, Fort.Longitude) = \
transform_from_wgs_to_gcj(Location(Fort.Latitude, Fort.Longitude))
                            if Fort.GymPoints and args.display_gym:
                                gyms[Fort.FortId] = [Fort.Team, Fort.Latitude,
                                                     Fort.Longitude, Fort.GymPoints]

                            elif Fort.FortType \
                                and args.display_pokestop:
                                expire_time = 0
                                if Fort.LureInfo.LureExpiresTimestampMs:
                                    expire_time = datetime\
                                        .fromtimestamp(Fort.LureInfo.LureExpiresTimestampMs / 1000.0)\
                                        .strftime("%H:%M:%S")
                                if (expire_time != 0 or not args.onlylure):
                                    pokestops[Fort.FortId] = [Fort.Latitude,
                                                              Fort.Longitude, expire_time]
        except AttributeError:
            # Reset login session if problems happen
            global login_session, global_token
            login_session = None
            global_token = None
            break

    for poke in visible:
        pokeid = str(poke.pokemon.PokemonId)
        pokename = pokemonsJSON[pokeid]
        if args.ignore:
            if pokename.lower() in ignore or pokeid in ignore:
                continue
        elif args.only:
            if pokename.lower() not in only and pokeid not in only:
                continue

        error_text1 = ''
        error_text2 = ''
        error_br = ''
        if poke.TimeTillHiddenMs <= 0:
            print "[+] Found error time, setting to 15 minutes: " + str(poke.TimeTillHiddenMs)
            poke.TimeTillHiddenMs = 900000
            error_text1 = '(!) '
            error_text2 = 'Error: disappear_time was invalid, set to 15 minutes instead.'
            error_br = '<br>'
        disappear_timestamp = time.time() + poke.TimeTillHiddenMs \
            / 1000

        if args.china:
            (poke.Latitude, poke.Longitude) = \
                transform_from_wgs_to_gcj(Location(poke.Latitude,
                    poke.Longitude))

        datestr = datetime.fromtimestamp(disappear_timestamp)
        dateoutput = datestr.strftime("%H:%M:%S")
        if is_ampm_clock:
            dateoutput = datestr.strftime("%I:%M:%S%p").lstrip('0')

        pokemon_obj = {
            "lat": poke.Latitude,
            "lng": poke.Longitude,
            "disappear_time": disappear_timestamp,
            "id": poke.pokemon.PokemonId,
            "name": pokename,
            "error_text1": error_text1,
            "error_text2": error_text2,
            "error_br": error_br,
            "disappear_time_formatted": dateoutput
        }

        pokespawnkey = poke.SpawnPointId + pokename
        if pokespawnkey not in pokemons:
            pushbullet_iden = notifier.pokemon_found(pokemon_obj)
            pokemon_obj['pushbullet_iden'] = pushbullet_iden
            pokemons[pokespawnkey] = pokemon_obj