Exemplo n.º 1
0
def get_worker_markers():
    markers = []
    points = utils.get_points_per_worker()
    # Worker start points
    for worker_no, worker_points in enumerate(points):
        coords = utils.get_start_coords(worker_no)
        markers.append({
            'icon': icons.dots.green,
            'lat': coords[0],
            'lng': coords[1],
            'infobox': 'Worker %d' % worker_no,
            'type': 'custom',
            'subtype': 'worker',
            'key': 'start-position-%d' % worker_no,
            'disappear_time': -1
        })
        # Circles
        for i, point in enumerate(worker_points):
            markers.append({
                'lat': point[0],
                'lng': point[1],
                'infobox': 'Worker %d point %d' % (worker_no, i),
                'subtype': 'point',
            })
    return markers
Exemplo n.º 2
0
def get_worker_markers():
    markers = []
    points = utils.get_points_per_worker()
    # Worker start points
    for worker_no, worker_points in enumerate(points):
        coords = utils.get_start_coords(worker_no)
        markers.append({
            'icon': icons.dots.green,
            'lat': coords[0],
            'lng': coords[1],
            'infobox': 'Worker %d' % worker_no,
            'type': 'custom',
            'subtype': 'worker',
            'key': 'start-position-%d' % worker_no,
            'disappear_time': -1
        })
        # Circles
        for i, point in enumerate(worker_points):
            markers.append({
                'lat': point[0],
                'lng': point[1],
                'infobox': 'Worker %d point %d' % (worker_no, i),
                'subtype': 'point',
            })
    return markers
Exemplo n.º 3
0
def get_pokemarkers():
    markers = []

    workers = app_config.GRID[0] * app_config.GRID[1]
    for i in range(workers):
        coords = utils.get_start_coords(i)
        markers.append(
            {
                "icon": icons.dots.red,
                "lat": coords[0],
                "lng": coords[1],
                "infobox": "Worker %d" % i,
                "type": "custom",
                "key": "start-position-%d" % i,
                "disappear_time": -1,
            }
        )

    session = db.Session()
    pokemons = db.get_sightings(session)
    session.close()

    for pokemon in pokemons:
        name = pokemon_names[str(pokemon.pokemon_id)]
        datestr = datetime.fromtimestamp(pokemon.expire_timestamp)
        dateoutput = datestr.strftime("%H:%M:%S")

        LABEL_TMPL = u"""
<div><b>{name}</b><span> - </span><small><a href='http://www.pokemon.com/us/pokedex/{id}' target='_blank' title='View in Pokedex'>#{id}</a></small></div>
<div>Disappears at - {disappear_time_formatted} <span class='label-countdown' disappears-at='{disappear_time}'></span></div>
<div><a href='https://www.google.com/maps/dir/Current+Location/{lat},{lng}' target='_blank' title='View in Maps'>Get Directions</a></div>
"""
        label = LABEL_TMPL.format(
            id=pokemon.pokemon_id,
            name=name,
            disappear_time=pokemon.expire_timestamp,
            disappear_time_formatted=dateoutput,
            lat=pokemon.lat,
            lng=pokemon.lon,
        )
        #  NOTE: `infobox` field doesn't render multiple line string in frontend
        label = label.replace("\n", "")

        markers.append(
            {
                "type": "pokemon",
                "name": name,
                "key": "{}-{}".format(pokemon.pokemon_id, pokemon.spawn_id),
                "disappear_time": pokemon.expire_timestamp,
                "icon": "static/icons/%d.png" % pokemon.pokemon_id,
                "lat": pokemon.lat,
                "lng": pokemon.lon,
                "pokemon_id": pokemon.pokemon_id,
                "infobox": label,
            }
        )

    return markers
Exemplo n.º 4
0
def get_pokemarkers():
    markers = []

    total_workers = app_config.GRID[0] * app_config.GRID[1]
    for worker_no in range(total_workers):
        coords = utils.get_start_coords(worker_no)
        markers.append({
            'icon': icons.dots.red,
            'lat': coords[0],
            'lng': coords[1],
            'infobox': 'Worker %d' % worker_no,
            'type': 'custom',
            'key': 'start-position-%d' % worker_no,
            'disappear_time': -1
        })

    session = db.Session()
    pokemons = db.get_sightings(session)
    session.close()

    for pokemon in pokemons:
        name = pokemon_names[str(pokemon.pokemon_id)]
        datestr = datetime.fromtimestamp(pokemon.expire_timestamp)
        dateoutput = datestr.strftime("%H:%M:%S")

        LABEL_TMPL = u'''
<div><b>{name}</b><span> - </span><small><a href='http://www.pokemon.com/us/pokedex/{id}' target='_blank' title='View in Pokedex'>#{id}</a></small></div>
<div>Disappears at - {disappear_time_formatted} <span class='label-countdown' disappears-at='{disappear_time}'></span></div>
<div><a href='https://www.google.com/maps/dir/Current+Location/{lat},{lng}' target='_blank' title='View in Maps'>Get Directions</a></div>
'''
        label = LABEL_TMPL.format(
            id=pokemon.pokemon_id,
            name=name,
            disappear_time=pokemon.expire_timestamp,
            disappear_time_formatted=dateoutput,
            lat=pokemon.lat,
            lng=pokemon.lon,
        )
        #  NOTE: `infobox` field doesn't render multiple line string in frontend
        label = label.replace('\n', '')

        markers.append({
            'type': 'pokemon',
            'name': name,
            'key': '{}-{}'.format(pokemon.pokemon_id, pokemon.spawn_id),
            'disappear_time': pokemon.expire_timestamp,
            'icon': 'static/icons/%d.png' % pokemon.pokemon_id,
            'lat': pokemon.lat,
            'lng': pokemon.lon,
            'pokemon_id': pokemon.pokemon_id,
            'infobox': label
        })

    return markers
Exemplo n.º 5
0
    def main(self, service, api_endpoint, access_token, profile_response):
        origin_lat, origin_lon = utils.get_start_coords(self.worker_no)

        pos = 1
        x = 0
        y = 0
        dx = 0
        dy = -1
        session = db.Session()
        self.seen = 0
        for step in range(self.steplimit2):
            add_to_db = []
            self.step = step + 1
            # Scan location math
            if (
                -self.steplimit2 / 2 < x <= self.steplimit2 / 2 and
                -self.steplimit2 / 2 < y <= self.steplimit2 / 2
            ):
                lat = x * 0.0025 + origin_lat
                lon = y * 0.0025 + origin_lon
            if x == y or x < 0 and x == -y or x > 0 and x == 1 - y:
                (dx, dy) = (-dy, dx)

            (x, y) = (x + dx, y + dy)

            process_step(
                service,
                api_endpoint,
                access_token,
                profile_response,
                add_to_db=add_to_db,
                lat=lat,
                lon=lon,
            )

            for spawn_id in add_to_db:
                pokemon = pokemons[spawn_id]
                db.add_sighting(session, spawn_id, pokemon)
                self.seen += 1
            session.commit()
            add_to_db = []
            logger.info(
                'Completed: %s%%',
                ((step + 1) + pos * .25 - .25) / (self.steplimit2) * 100
            )
            # Clear error code and let know that there are Pokemon
            if self.error_code and self.seen:
                self.error_code = None
        session.close()
        if self.seen == 0:
            self.error_code = 'NO POKEMON'
        set_location_coords(origin_lat, origin_lon, 0)
Exemplo n.º 6
0
def main(worker_no, service, api_endpoint, access_token, profile_response):
    origin_lat, origin_lon = utils.get_start_coords(worker_no)

    args = get_args()

    if args.debug:
        global DEBUG
        DEBUG = True
        print '[!] DEBUG mode on'

    steplimit = int(args.step_limit)

    pos = 1
    x = 0
    y = 0
    dx = 0
    dy = -1
    steplimit2 = steplimit**2
    session = db.Session()
    for step in range(steplimit2):
        add_to_db = []
        #starting at 0 index
        debug('looping: step {} of {}'.format((step+1), steplimit**2))
        # Scan location math
        if -steplimit2 / 2 < x <= steplimit2 / 2 and -steplimit2 / 2 < y <= steplimit2 / 2:
            lat = x * 0.0025 + origin_lat
            lon = y * 0.0025 + origin_lon
        if x == y or x < 0 and x == -y or x > 0 and x == 1 - y:
            (dx, dy) = (-dy, dx)

        (x, y) = (x + dx, y + dy)

        process_step(
            service,
            api_endpoint,
            access_token,
            profile_response,
            add_to_db=add_to_db,
            lat=lat,
            lon=lon,
        )

        for spawn_id in add_to_db:
            pokemon = pokemons[spawn_id]
            db.add_sighting(session, spawn_id, pokemon)
        session.commit()
        add_to_db = []
        print('Completed: ' + str(((step+1) + pos * .25 - .25) / (steplimit2) * 100) + '%')
    session.close()
    set_location_coords(origin_lat, origin_lon, 0)
Exemplo n.º 7
0
 def __init__(self, worker_no):
     self.worker_no = worker_no
     self.logger = getLogger('worker-{}'.format(worker_no))
     # account information
     try:
         self.account = self.extra_queue.get_nowait()
     except Empty as e:
         raise ValueError(
             "You don't have enough accounts for the number of workers specified in GRID."
         ) from e
     self.username = self.account['username']
     self.location = self.account.get('location',
                                      get_start_coords(worker_no))
     self.inventory_timestamp = self.account.get('inventory_timestamp')
     # last time of any request
     self.last_request = self.account.get('time', 0)
     # last time of a request that requires user interaction in the game
     self.last_action = self.last_request
     # last time of a GetMapObjects request
     self.last_gmo = self.last_request
     self.items = self.account.get('items', {})
     self.num_captchas = 0
     self.eggs = {}
     self.unused_incubators = []
     # API setup
     if self.proxies:
         self.new_proxy(set_api=False)
     self.initialize_api()
     # State variables
     self.busy = BusyLock()
     self.killed = False
     # Other variables
     self.after_spawn = None
     self.speed = 0
     self.account_start = None
     self.total_seen = 0
     self.error_code = 'INIT'
     self.item_capacity = 350
     self.visits = 0
     self.pokestops = config.SPIN_POKESTOPS
     self.next_spin = 0
Exemplo n.º 8
0
    def bootstrap_one(self):
        async def visit_release(worker, point):
            try:
                await worker.busy.acquire()
                if await worker.bootstrap_visit(point):
                    self.visits += 1
            finally:
                try:
                    worker.busy.release()
                except (NameError, AttributeError, RuntimeError):
                    pass
                self.coroutine_semaphore.release()

        for worker in self.workers:
            number = worker.worker_no
            worker.bootstrap = True
            point = list(get_start_coords(number))
            time.sleep(.25)
            self.coroutine_semaphore.acquire()
            asyncio.run_coroutine_threadsafe(visit_release(worker, point),
                                             loop=self.loop)
Exemplo n.º 9
0
def get_worker_markers():
    markers = []
    points = utils.get_points_per_worker()
    # Worker start points
    for worker_no, worker_points in enumerate(points):
        coords = utils.get_start_coords(worker_no)
        markers.append({
            'lat': coords[0],
            'lon': coords[1],
            'type': 'worker',
            'worker_no': worker_no,
        })
        # Circles
        for i, point in enumerate(worker_points):
            markers.append({
                'lat': point[0],
                'lon': point[1],
                'type': 'worker_point',
                'worker_no': worker_no,
                'point_no': i,
            })
    return markers
Exemplo n.º 10
0
def get_worker_markers():
    markers = []
    points = utils.get_points_per_worker()
    # Worker start points
    for worker_no, worker_points in enumerate(points):
        coords = utils.get_start_coords(worker_no)
        markers.append({
            'lat': coords[0],
            'lon': coords[1],
            'type': 'worker',
            'worker_no': worker_no,
        })
        # Circles
        for i, point in enumerate(worker_points):
            markers.append({
                'lat': point[0],
                'lon': point[1],
                'type': 'worker_point',
                'worker_no': worker_no,
                'point_no': i,
            })
    return markers
Exemplo n.º 11
0
def get_pokemarkers():
    markers = []

    total_workers = app_config.GRID[0] * app_config.GRID[1]
    for worker_no in range(total_workers):
        coords = utils.get_start_coords(worker_no)
        markers.append({
            'icon': icons.dots.red,
            'lat': coords[0],
            'lng': coords[1],
            'infobox': 'Worker %d' % worker_no,
            'type': 'custom',
            'key': 'start-position-%d' % worker_no,
            'disappear_time': -1
        })

    session = db.Session()
    pokemons = db.get_sightings(session)
    session.close()

    for pokemon in pokemons:
        name = pokemon_names[str(pokemon.pokemon_id)]
        datestr = datetime.fromtimestamp(pokemon.expire_timestamp)
        dateoutput = datestr.strftime("%H:%M:%S")

        LABEL_TMPL = u'''
<div><b>{name}</b><span> - </span><small><a href='http://www.pokemon.com/us/pokedex/{id}' target='_blank' title='View in Pokedex'>#{id}</a></small></div>
<div>Disappears at - {disappear_time_formatted} <span class='label-countdown' disappears-at='{disappear_time}'></span></div>
<div><a href='https://www.google.com/maps/dir/Current+Location/{lat},{lng}' target='_blank' title='View in Maps'>Get Directions</a></div>
'''
        label = LABEL_TMPL.format(
            id=pokemon.pokemon_id,
            name=name,
            disappear_time=pokemon.expire_timestamp,
            disappear_time_formatted=dateoutput,
            lat=pokemon.lat,
            lng=pokemon.lon,
        )
        #  NOTE: `infobox` field doesn't render multiple line string in frontend
        label = label.replace('\n', '')

        markers.append({
            'type':
            'pokemon',
            'name':
            name,
            'key':
            '{}-{}'.format(pokemon.pokemon_id, pokemon.spawn_id),
            'disappear_time':
            pokemon.expire_timestamp,
            'icon':
            'static/icons/%d.png' % pokemon.pokemon_id,
            'lat':
            pokemon.lat,
            'lng':
            pokemon.lon,
            'pokemon_id':
            pokemon.pokemon_id,
            'infobox':
            label
        })

    return markers