Exemplo n.º 1
0
def update_ex_gyms(geofence):
    # Parse geofence file.
    log.info('Finding border points from geofence.')
    geofence = Geofences.parse_geofences_file(geofence, '')
    fence = geofence[0]['polygon']

    # Figure out borders for bounding box.
    south = min(fence, key=lambda ev: ev['lat'])['lat']
    west = min(fence, key=lambda ev: ev['lon'])['lon']
    north = max(fence, key=lambda ev: ev['lat'])['lat']
    east = max(fence, key=lambda ev: ev['lon'])['lon']

    log.info('Finding parks within zone.')
    ex_gyms = ex_query(south, west, north, east)
    gyms = Gym.get_gyms(south, west, north, east)

    if not gyms:
        log.error('No gyms detected within geofence, exiting.')
        exit(1)

    log.info('Checking {} gyms against {} parks.'.format(
        len(gyms), len(ex_gyms.ways)))
    # Retrieve list of confirmed EX gyms to update the DB.
    confirmed_ex_gyms = filter(lambda gym: __gym_is_ex_gym(gym, ex_gyms),
                               gyms.values())

    if not confirmed_ex_gyms:
        log.info('No EX-eligible gyms found.')
        exit(1)
    Gym.set_gyms_in_park(confirmed_ex_gyms, True)
Exemplo n.º 2
0
def exgyms(geofence):
    # Parse geofence file
    log.info('Finding border points from geofence')
    f = json.loads(json.dumps(Geofences.parse_geofences_file(geofence, '')))
    fence = f[0]['polygon']
    # Figure out borders for bounding box
    south = min(fence, key=lambda ev: ev['lat'])['lat']
    west = min(fence, key=lambda ev: ev['lon'])['lon']
    north = max(fence, key=lambda ev: ev['lat'])['lat']
    east = max(fence, key=lambda ev: ev['lon'])['lon']
    log.info('Finding parks within zone')
    ex_gyms = ex_query(south, west, north, east)

    gyms = Gym.get_gyms(south, west, north, east)
    log.info('Checking {} gyms against {} parks'.format(len(gyms),
                                                        len(ex_gyms.ways)))
    for way in ex_gyms.ways:
        data = []
        for node in way.nodes:
            data.append({'lat': float(node.lat),
                         'lon': float(node.lon)})

        for gym in gyms.items():

            gympoint = {'lat': float(gym[1]['latitude']),
                        'lon': float(gym[1]['longitude'])}
            # Check if gyms falls within a designated park and update if park
            if Geofences.is_point_in_polygon_custom(gympoint, data):

                # Try to get Gym name, but default to id if missing
                try:
                    gymname = Gym.get_gym(gym[0])['name'].encode('utf8')
                except AttributeError:
                    gymname = gym[0]
                log.info('{} is eligible for legendary raid'.format(gymname))
                Gym.is_gym_park(gym[0], True)