Skip to content

Commit 03d4bf1

Browse files
committed
dynamic sleep, auth exception handling
1 parent 26fbfe7 commit 03d4bf1

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tracker.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from s2sphere import CellId
1313
from time import sleep
1414

15-
from pgoapi.exceptions import NotLoggedInException
15+
from pgoapi.exceptions import NotLoggedInException, AuthException
1616
from ext import api_init, get_pokelist, get_pokenames, hex_spiral, get_cell_ids, cover_circle, circle_in_cell
1717

1818
log = logging.getLogger(__name__)
@@ -58,13 +58,12 @@ def init_config():
5858

5959
def main():
6060

61+
lastscan = datetime.now()
62+
6163
config = init_config()
6264
if not config:
6365
return
6466

65-
Ptargets,Pfound,Pactive = [],[],[]
66-
lastscan = datetime.now()
67-
6867
log.info("Log'in...")
6968
api = api_init(config)
7069

@@ -86,6 +85,7 @@ def main():
8685
log.info('Generating Hexgrid...')
8786
grid = hex_spiral(olat, olng, 200, config.layers)
8887

88+
Ptargets,Pfound,Pactive = [],[],[]
8989
while True:
9090

9191
m = 1
@@ -106,8 +106,8 @@ def main():
106106
timestamps = [0,] * len(cell_ids)
107107
api.set_position(plat, plng, alt)
108108
try: response_dict = api.get_map_objects(latitude=plat, longitude=plng, since_timestamp_ms = timestamps, cell_id = cell_ids)
109-
except NotLoggedInException: api = None; api = api_init(config); sleep(10)
110-
lastscan = datetime.now()
109+
except NotLoggedInException, AuthException: api = None; api = api_init(config)
110+
finally: lastscan = datetime.now()
111111
# coarse
112112
Ctargets = []
113113
for map_cell in response_dict['responses']['GET_MAP_OBJECTS']['map_cells']:
@@ -158,17 +158,19 @@ def main():
158158
if spos in Sdone: continue
159159

160160
slat,slng = spos[0],spos[1]
161-
162161
cell_ids = get_cell_ids(cover_circle(slat, slng, 75, 15))
162+
163+
while datetime.now() < (lastscan + timedelta(seconds=10)): sleep(0.5)
164+
163165
log.info('Looking closer for %d pokes, step %d (max %d)' % (len(Ptargets),s,len(subgrid)))
164166

165167
response_dict = None
166168
while response_dict is None:
167-
sleep(10)
168169
timestamps = [0,] * len(cell_ids)
169170
api.set_position(slat, slng, alt)
170171
try: response_dict = api.get_map_objects(latitude=slat, longitude=slng, since_timestamp_ms = timestamps, cell_id = cell_ids)
171-
except NotLoggedInException: api = None; api = api_init(config)
172+
except NotLoggedInException, AuthException: api = None; api = api_init(config)
173+
finally: lastscan = datetime.now()
172174

173175
for map_cell in response_dict['responses']['GET_MAP_OBJECTS']['map_cells']:
174176
if 'catchable_pokemons' in map_cell:

0 commit comments

Comments
 (0)