forked from free5ty1e/pokemongo-python
/
main.py
97 lines (62 loc) · 4.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import time
from datetime import timedelta
from datetime import datetime
from pytz import timezone
import re
from skiplagged import Skiplagged
from pushbullet import Pushbullet
from googlemaps import Client
from utils.pokemon import is_unique
if __name__ == '__main__':
client = Skiplagged()
pb = Pushbullet(os.getenv("PB_KEY"))
gmaps = Client(os.getenv("GMAP_KEY"))
#bounds = client.get_bounds_for_address('Isla Vista, CA')
bounds = (
(34.408359, -119.869816), # Lower left lat, lng
(34.420923, -119.840293) # Upper right lat, lng
)
for channel in pb.channels:
print channel
if channel.channel_tag == '':
my_channel = channel
print my_channel
notify = ['Venasaur','Blastoise', 'Charizard', 'Raichu', 'Nidoqueen', 'Nidoking', 'Clefable', 'Ninetales', 'Vileplume', 'Golduck', 'Arcanine', 'Poliwrath', 'Kadabra', 'Alakazam', 'Machamp', 'Victreebel', 'Golem', 'Slowbro', 'Rapidash', 'Farfetch\'d', 'Dewgong', 'Muk', 'Cloyster', 'Gengar', 'Hypno', 'Exeggutor', 'Hitmonchan', 'Hitmonlee', 'Lickitung', 'Weezing', 'Rhydon', 'Chansey', 'Tangela', 'Kangaskhan', 'Starmie', 'Mr. Mime', 'Scyther', 'Jynx', 'Electabuzz', 'Magmar', 'Pinsir', 'Tauros', 'Gyarados', 'Lapras', 'Snorlax', 'Ditto', 'Vaporeon', 'Jolteon', 'Flareon', 'Porygon', 'Omastar', 'Kabutops', 'Aerodactyl', 'Snorlax', 'Articuno', 'Zapdos', 'Moltres', 'Dragonair', 'Dragonite', 'Mewtwo', 'Mew' ]
archive = []
while 1:
try:
# Log in with a Google or Pokemon Trainer Club account
#print client.login_with_pokemon_trainer('username', 'password')
print client.login_with_google(os.getenv("USERNAME"), os.getenv("PASSWORD"))
# Get specific Pokemon Go API endpoint
print client.get_specific_api_endpoint()
# Get profile
print client.get_profile()
# Find pokemon
for pokemon in client.find_pokemon(bounds):
print pokemon
print pokemon.get_expires_timestamp()
print time.time()
id = pokemon.get_name()
if id in notify:
PST = timezone('US/Pacific')
expires_time = pokemon.get_expires().replace(tzinfo=timezone('UTC')).astimezone(PST)
address = gmaps.reverse_geocode((pokemon.get_location()["latitude"], pokemon.get_location()["longitude"]))[0]['address_components']
formatted_address = address[0]['short_name'] + ' ' + address[1]['short_name'] + ', ' + address[2]['short_name']
message = "%s at %s.\nExpires at %s:%02d:%02d (in %d:%02d)" % (pokemon.get_name(), formatted_address, expires_time.strftime("%-I"), expires_time.minute, expires_time.second, int(pokemon.sec_till_expire()/60), pokemon.sec_till_expire()%60)
#mapslink = 'http://maps.apple.com/?q=%s&ll=%f,%f&z=18' % (pokemon.get_name(), pokemon.get_location()["latitude"], pokemon.get_location()["longitude"])
mapslink = 'http://maps.apple.com/?q=%f,%f&ll=%f,%f&z=18' % (pokemon.get_location()["latitude"], pokemon.get_location()["longitude"], pokemon.get_location()["latitude"], pokemon.get_location()["longitude"])
print mapslink
if is_unique(pokemon, archive) and int(pokemon.sec_till_expire()/60) > 0:
archive.append(pokemon)
my_channel.push_note("Wild "+ pokemon.get_name().upper() + " appeared!", message + '\n' + mapslink)
print "\nWild "+ pokemon.get_name().upper() + " appeared!\n", message + '\n' + mapslink
print "%d in archive" % (len(archive))
for found in archive:
if int(found.get_expires_timestamp() - time.time()) <= 0:
print 'Removed: ' + found.get_name()
archive.remove(found)
except Exception as e:
print "exception:", e
time.sleep(1)