示例#1
0
def raw_data():
    """ Gets raw data for pokemons/gyms/pokestops via REST """
    pokemons, gyms, pokestops = [], [], []
    for pokemon in Pokemon.select():
        pokemons.append(model_to_dict(pokemon))
    for gym in Gym.select():
        gyms.append(model_to_dict(gym))
    for pokestop in Pokestop.select():
        pokestops.append(model_to_dict(pokestop))
    return flask.jsonify(
        pokemons=pokemons,
        gyms=gyms,
        pokestops=pokestops
    )
示例#2
0
def get_pokemarkers():
    pokeMarkers = [{
        'icon': icons.dots.red,
        'lat': origin_lat,
        'lng': origin_lon,
        'infobox': "Start position",
        'type': 'custom',
        'key': 'start-position',
        'disappear_time': -1
    }]

    for pokemon in Pokemon.select():
        label_mapping = {}
        label_mapping['disappear_time_formatted'] = datetime.fromtimestamp(pokemon.disappear_time).strftime("%H:%M:%S")
        label_mapping['id'] = pokemon.pokedex_num
        label_mapping['disappear_time'] = pokemon.disappear_time
        label_mapping['name'] = pokemon.name
        label_mapping['lat'] = pokemon.lat
        label_mapping['lon'] = pokemon.lon

        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},{lon}' target='_blank' title='View in Maps'>Get Directions</a></div>
'''
        label = LABEL_TMPL.format(**label_mapping)
        #  NOTE: `infobox` field doesn't render multiple line string in frontend
        label = label.replace('\n', '')

        pokeMarkers.append({
            'type': 'pokemon',
            'icon': 'static/icons/%d.png' % pokemon.pokedex_num,
            'lat': pokemon.lat,
            'lng': pokemon.lon,
            'key': pokemon.spawnpoint_id,
            'disappear_time': pokemon.disappear_time,
            'infobox': label
        })

    if args.display_gym:
        for gym in Gym.select():
            if gym.team_id == 0:
                color = "rgba(0,0,0,.4)"
            if gym.team_id == 1:
                color = "rgba(0, 0, 256, .4)"
            if gym.team_id == 2:
                color = "rgba(255, 0, 0, .4)"
            if gym.team_id == 3:
                color = "rgba(255, 255, 0, .4)"

        icon = 'static/forts/'+gym.team_name+'_large.png'
        pokeMarkers.append({
            'icon': 'static/forts/' + gym.team_name + '.png',
            'type': 'gym',
            'key': gym.gym_id,
            'disappear_time': -1,
            'lat': gym.lat,
            'lng': gym.lon,
            'infobox': "<div><center><small>Gym owned by:</small><br><b style='color:" + color + "'>Team " +
                       gym.team_name + "</b><br><img id='" + gym.team_name + "' height='100px' src='" + icon + "'></center>"

        })

    if args.display_pokestop:
        for pokestop in Pokestop.select():
            pokeMarkers.append({
                'type': 'stop',
                'key': pokestop.pokestop_id,
                'disappear_time': -1,
                'icon': 'static/forts/Pstop.png',
                'infobox': 'Pokestop',
                'lng': pokestop.lon,
                'lat': pokestop.lat,
            })
    return pokeMarkers