def get_pokeDiscord(): data = [] # Get the Pokemon out of the Database 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") data.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 }) return data
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
async def check_pokemon(): session = db.Session() pokemons = db.get_sightings(session) session.close() for sighting in pokemons: await process_sighting(sighting) remove_stale_sightings()
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
def get_pokemarkers(): markers = [] session = db.Session() if args.after == 0: pokemons = db.get_sightings(session) else: pokemons = db.get_sightings_after(session, args.after) forts = db.get_forts(session) pokestops = db.get_pokestops(session) session.close() for pokemon in pokemons: markers.append({ 'id': 'pokemon-{}'.format(pokemon.id), 'type': 'pokemon', 'trash': pokemon.pokemon_id in config.TRASH_IDS, 'name': POKEMON_NAMES[pokemon.pokemon_id], 'pokemon_id': pokemon.pokemon_id, 'lat': pokemon.lat, 'lon': pokemon.lon, 'expires_at': pokemon.expire_timestamp, }) for fort in forts: if fort['guard_pokemon_id']: pokemon_name = POKEMON_NAMES[fort['guard_pokemon_id']] else: pokemon_name = 'Empty' markers.append({ 'id': 'fort-{}'.format(fort['fort_id']), 'sighting_id': fort['id'], 'type': 'fort', 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': pokemon_name, 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'], }) for pokestop in pokestops: markers.append({ 'id': 'stop-{}'.format(pokestop['id']), 'type': 'pokestop', 'lat': pokestop['lat'], 'lon': pokestop['lon'], }) return markers
def get_pokemarkers(): markers = [] session = db.Session() pokemons = db.get_sightings(session) forts = db.get_forts(session) stops = db.get_stops(session) session.close() for pokemon in pokemons: markers.append({ 'id': 'pokemon-{}'.format(pokemon.id), 'type': 'pokemon', 'trash': pokemon.pokemon_id in config.TRASH_IDS, 'name': pokemon_names[str(pokemon.pokemon_id)], 'pokemon_id': pokemon.pokemon_id, 'lat': pokemon.lat, 'lon': pokemon.lon, 'expires_at': pokemon.expire_timestamp, }) for fort in forts: if fort['guard_pokemon_id']: pokemon_name = pokemon_names[str(fort['guard_pokemon_id'])] else: pokemon_name = 'Empty' markers.append({ 'id': 'fort-{}'.format(fort['fort_id']), 'sighting_id': fort['id'], 'type': 'fort', 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': pokemon_name, 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'], }) for stop in stops: if stop['active_pokemon_id'] != 0: pokemon_name = pokemon_names[str(stop['active_pokemon_id'])] else: pokemon_name = 'No Lure' markers.append({ 'id': 'stop-{}'.format(stop['stop_id']), 'sighting_id': stop['id'], 'type': 'stop', 'lure_expires_timestamp': stop['lure_expires_timestamp_ms'], 'pokemon_id': stop['active_pokemon_id'], 'pokemon_name': pokemon_name, 'lat': stop['lat'], 'lon': stop['lon'], }) return markers
def get_pokemarkers(): markers = [] 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
def get_pokemarkers(): markers = [] session = db.Session(autoflush=False) pokemons = db.get_sightings(session) forts = db.get_forts(session) session.close() for pokemon in pokemons: markers.append({ 'id': 'pokemon-{}'.format(pokemon.id), 'type': 'pokemon', 'trash': pokemon.pokemon_id in config.TRASH_IDS, 'name': POKEMON_NAMES[pokemon.pokemon_id], 'pokemon_id': pokemon.pokemon_id, 'lat': pokemon.lat, 'lon': pokemon.lon, 'expires_at': pokemon.expire_timestamp, }) for fort in forts: if fort['guard_pokemon_id']: pokemon_name = POKEMON_NAMES[fort['guard_pokemon_id']] else: pokemon_name = 'Empty' markers.append({ 'id': 'fort-{}'.format(fort['fort_id']), 'sighting_id': fort['id'], 'type': 'fort', 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': pokemon_name, 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'], }) if config.MAP_WORKERS: # Worker stats markers.extend(get_worker_markers()) return markers
def get_pokemarkers(): markers = [] session = db.Session() pokemons = db.get_sightings(session) forts = db.get_forts(session) session.close() for pokemon in pokemons: markers.append({ 'id': 'pokemon-{}'.format(pokemon.id), 'type': 'pokemon', 'trash': pokemon.pokemon_id in config.TRASH_IDS, 'name': POKEMON_NAMES[pokemon.pokemon_id], 'pokemon_id': pokemon.pokemon_id, 'lat': pokemon.lat, 'lon': pokemon.lon, 'expires_at': pokemon.expire_timestamp, }) for fort in forts: if fort['guard_pokemon_id']: pokemon_name = POKEMON_NAMES[fort['guard_pokemon_id']] else: pokemon_name = 'Empty' markers.append({ 'id': 'fort-{}'.format(fort['fort_id']), 'sighting_id': fort['id'], 'type': 'fort', 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': pokemon_name, 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'], }) return markers
def PokListener(bot): session = db.Session() pokemons = db.get_sightings(session) session.close() pokeids = [2,3,5,6,8,9,26,31,34,38,55,64,65,68,73,82,83,88,89,91,92,93,94,97,110,115,117,121,122,123,124,125,128,130,131,132,134,135,136,137,139,142,143,144,145,147,146,148,149,150,151] # List of Pokemon we want to show. commonPok = [64, 122, 147] # we'll store some rare Pokemons but common in our zone. This will trigger a RNG. now = time.time() for pokemon in pokemons: if abs(pokemon.expire_timestamp) > now: time_remaining = abs(pokemon.expire_timestamp) - now if time_remaining >= 200: if pokemon.spawn_id not in allPokList: if pokemon.pokemon_id in pokeids: # uncomment the block above to limit the alerts to some Pokemon (for example, there will be a pertentage to send alert if Flareon, Electrabuz...) '''if pokemon.pokemon_id in commonPok: gluck = random.randint(0, 1) # 50%... if gluck == 0: allPokList.append(pokemon.spawn_id) continue''' name = pokemon_names[str(pokemon.pokemon_id)] datestr = datetime.fromtimestamp(pokemon.expire_timestamp) dateoutput = datestr.strftime("%H:%M:%S") location = geolocator.reverse((pokemon.lat, pokemon.lon), True) useloc = location.address.split(', 230') #this is used to trim the location. If string is >140 chars, Twitter API will crash. Change to the first digits of your ZIP code. If ZIP code is 23002, i'll put 230 print '[-] A ' + name + ' was found in ' + useloc[0] + '. ' + str(round(time_remaining)) + 's remaining.' allPokList.append(pokemon.spawn_id) message = EmojiFromRank(PokIDtoStars(pokemon.pokemon_id)) + ' <b>' + name + '</b> was found in <a href="https://www.google.com/maps/dir/Current+Location/'+ pokemon.lat +',' + pokemon.lon +'">' + useloc[0] + '</a>. Disappear time: <b>' + dateoutput + '</b>' bot.sendMessage('@CHANNEL/GROUP', message, 'html') # the @name of your channel/group. The bot MUST be added as administrator if channel. bot.sendLocation('@CHANNEL/GROUP', pokemon.lat, pokemon.lon) # same, the @name of your channel/group where the location will be send to. # UNCOMMENT THIS BLOCK TO USE TWITTER '''twdatestr = datetime.fromtimestamp(now)
def checkPokemons(): with app.app_context(): print(str(time.ctime())+': checking pokemons...') msg = Message( 'A Wild Pokémon appeared!', sender='*****@*****.**', recipients=['*****@*****.**','*****@*****.**','*****@*****.**'] ) mailPokemons = '' session = db.Session() pokemons = db.get_sightings(session) session.close() for pokemon in pokemons: name = pokemon_names[str(pokemon.pokemon_id)] if not blacklist.get(name,False): datestr = datetime.fromtimestamp(pokemon.expire_timestamp) dateoutput = datestr.strftime("%H:%M:%S") if alertlist.get(name,False): if not alreadySent.get(name+str(pokemon.expire_timestamp),False): print('Found '+name) alreadySent[name+str(pokemon.expire_timestamp)] = True with app.open_resource("static/icons/"+str(pokemon.pokemon_id)+".png") as fp: msg.attach(str(pokemon.pokemon_id)+".png", "image/png", fp.read(), headers=[['Content-ID', "<"+str(pokemon.pokemon_id)+">"],['Content-Disposition', 'inline']]) TPL = u'''<tr><td><img src='cid:{cid}'></td><td><b>{name}</b></td><td>{dateoutput}</td><td>{lat},{lng}</td><td><a href='https://www.google.com/maps/dir/Current+Location/{lat},{lng}' target='_blank'>Google Maps</a></td></tr>''' mailPokemons+= TPL.format( cid=pokemon.pokemon_id, name=name, dateoutput=dateoutput, lat=pokemon.lat, lng=pokemon.lon, ) print('\"'+mailPokemons+'\"') if bool(mailPokemons.strip()): sendMail(msg,"<table>"+mailPokemons+"</table>") else: print('nothing...')
def get_pokemarkers(): markers = [] session = db.Session() pokemons = db.get_sightings(session) forts = db.get_forts(session) session.close() global email_sent global tweets_sent TWITTER_1 = 0 TWITTER_2 = 0 TWITTER_3 = 0 TWITTER_4 = 0 PASSWORD = 0 for pokemon in pokemons: markers.append({ 'id': 'pokemon-{}'.format(pokemon.id), 'type': 'pokemon', 'trash': pokemon.pokemon_id in config.TRASH_IDS, 'name': POKEMON_NAMES[pokemon.pokemon_id], 'pokemon_id': pokemon.pokemon_id, 'lat': pokemon.lat, 'lon': pokemon.lon, 'expires_at': pokemon.expire_timestamp, }) name = POKEMON_NAMES[pokemon.pokemon_id] datestr = datetime.fromtimestamp(pokemon.expire_timestamp) dateoutput = datestr.strftime("%H:%M:%S") am_or_pm = " AM" temp_dateoutput = datestr.strftime("%H:%M:%S") time_now = datetime.now() diff_in_time = datestr - time_now diff_in_time_str_useless = str(diff_in_time).split(".") diff_in_time_str = diff_in_time_str_useless[0].split(":") diff_in_time_int = [int(i) for i in diff_in_time_str] mins = '' secs = '' if diff_in_time_int[1] is 1: mins = 'min ' else: mins = 'mins ' if diff_in_time_int[2] is 1: secs = 'sec ' else: secs = 'secs ' time_left_str = str(diff_in_time_int[1]) + mins + str( diff_in_time_int[2]) + secs mod_date = temp_dateoutput.split(":") mod_date_int = int(mod_date[0]) if mod_date_int > 24: mod_date_int = mod_date_int - 24 am_or_pm = " AM" elif mod_date_int == 24: mod_date_int = mod_date_int - 12 am_or_pm = " AM" elif mod_date_int > 12: mod_date_int = mod_date_int - 12 am_or_pm = " PM" elif mod_date_int == 12: am_or_pm = " PM" actual_dateoutput = str( mod_date_int) + ":" + mod_date[1] + ":" + mod_date[2] + am_or_pm new_lat = "%.8f" % float(pokemon.lat) new_lon = "%.8f" % float(pokemon.lon) missing = [ 2, 3, 5, 6, 24, 28, 38, 51, 53, 57, 62, 65, 67, 68, 76, 78, 82, 83, 85, 89, 101, 103, 107, 112, 113, 114, 115, 122, 130, 132, 139, 141, 144, 145, 146, 149, 150, 151 ] rare = [ 2, 3, 5, 6, 9, 24, 26, 28, 31, 34, 38, 40, 51, 53, 57, 59, 62, 65, 67, 68, 71, 76, 78, 82, 83, 84, 85, 87, 88, 89, 91, 94, 101, 103, 105, 106, 107, 110, 112, 113, 114, 115, 121, 122, 126, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 148, 149, 150, 151 ] rare_alert = "" if pokemon.pokemon_id in rare: rare_alert = "Rare Alert! " if pokemon.pokemon_id in missing and pokemon.expire_timestamp not in email_sent: msg = MIMEMultipart() msg['Subject'] = rare_alert + str(name) + " here 'til " + str( actual_dateoutput) + ' with ' + time_left_str + 'left' msg['From'] = "*****@*****.**" msg['To'] = "*****@*****.**" message_to_send = 'https://www.google.com/maps/dir/Current+Location/' + str( pokemon.lat) + ',' + str(pokemon.lon) part1 = MIMEText(message_to_send, 'plain') msg.attach(part1) print msg.as_string() server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login("*****@*****.**", PASSWORD) server.sendmail("*****@*****.**", "*****@*****.**", msg.as_string()) email_sent.append(pokemon.expire_timestamp) tweet_pokemon = [ 2, 3, 5, 6, 8, 9, 24, 26, 27, 28, 31, 34, 36, 37, 38, 40, 45, 50, 51, 53, 55, 57, 59, 61, 62, 64, 65, 67, 68, 71, 73, 75, 76, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 91, 94, 95, 99, 101, 103, 104, 105, 106, 107, 108, 110, 112, 113, 114, 115, 117, 121, 122, 123, 126, 127, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 148, 149, 150, 151 ] if pokemon.pokemon_id in tweet_pokemon and pokemon.expire_timestamp not in tweets_sent: message_to_send = rare_alert + str(name) + " here until " + str( actual_dateoutput ) + ' with ' + time_left_str + 'left! https://www.google.com/maps/dir/Current+Location/' + str( new_lat) + ',' + str(new_lon) auth = tweepy.OAuthHandler(TWITTER_1, TWITTER_2) auth.set_access_token(TWITTER_3, TWITTER_3) api = tweepy.API(auth) try: api.update_status(status=message_to_send) print message_to_send print len(message_to_send) except: print message_to_send tweets_sent.append(pokemon.expire_timestamp) for fort in forts: if fort['guard_pokemon_id']: pokemon_name = POKEMON_NAMES[fort['guard_pokemon_id']] else: pokemon_name = 'Empty' markers.append({ 'id': 'fort-{}'.format(fort['fort_id']), 'sighting_id': fort['id'], 'type': 'fort', 'prestige': fort['prestige'], 'pokemon_id': fort['guard_pokemon_id'], 'pokemon_name': pokemon_name, 'team': fort['team'], 'lat': fort['lat'], 'lon': fort['lon'], }) return markers