diff --git a/README.md b/README.md index 7c516c7c8d..7e33783998 100644 --- a/README.md +++ b/README.md @@ -379,6 +379,7 @@ If using multiple usernames format like this: * Leaklessgfy * codybaldwin * skyl1ne94 + * Heihachi ------- ## Credits diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index e9c2c9ee4b..b6b9bd9e7b 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -41,6 +41,45 @@ def take_step(self): for cell in cells: self.work_on_cell(cell, location) + def update_web_location(self, cells=[], lat=None, lng=None, alt=None): + # we can call the function with no arguments and still get the position and map_cells + if lat == None: + lat = self.position[0] + if lng == None: + lng = self.position[1] + if alt == None: + alt = self.position[2] + + if cells == []: + cellid = get_cellid(lat, lng) + timestamp = [0, ] * len(cellid) + self.api.get_map_objects( + latitude=f2i(lat), + longitude=f2i(lng), + since_timestamp_ms=timestamp, + cell_id=cellid + ) + response_dict = self.api.call() + map_objects = response_dict.get('responses', {}).get('GET_MAP_OBJECTS', {}) + status = map_objects.get('status', None) + cells = map_objects['map_cells'] + + user_web_location = 'web/location-%s.json' % (self.config.username) + # should check if file exists first but os is not imported here + # alt is unused atm but makes using *location easier + with open(user_web_location,'w') as outfile: + json.dump( + {'lat': lat, + 'lng': lng, + 'alt': alt, + 'cells': cells + }, outfile) + + user_data_lastlocation = 'data/last-location-%s.json' % (self.config.username) + with open(user_data_lastlocation, 'w') as outfile: + outfile.truncate() + json.dump({'lat': lat, 'lng': lng}, outfile) + def find_close_cells(self, lat, lng): cellid = get_cellid(lat, lng) timestamp = [0, ] * len(cellid) @@ -66,6 +105,7 @@ def find_close_cells(self, lat, lng): x['forts'][0]['latitude'], x['forts'][0]['longitude']) if x.get('forts', []) else 1e6 ) + self.update_web_location(map_cells,lat,lng) return map_cells def work_on_cell(self, cell, position): @@ -276,6 +316,8 @@ def _setup_api(self): logger.log('[#]') self.update_inventory() + # send empty map_cells and then our position + self.update_web_location([],*self.position) def catch_pokemon(self, pokemon): worker = PokemonCatchWorker(pokemon, self) @@ -325,7 +367,7 @@ def update_inventory(self): continue self.inventory.append(item['inventory_item_data'][ 'item']) - + def pokeball_inventory(self): self.api.get_player().get_inventory() @@ -495,6 +537,7 @@ def heartbeat(self): self.api.get_inventory() self.api.check_awarded_badges() self.api.call() + self.update_web_location() # updates every tick def get_inventory_count(self, what): self.api.get_inventory() diff --git a/pokemongo_bot/step_walker.py b/pokemongo_bot/step_walker.py index e0fb64bf00..08c643affb 100644 --- a/pokemongo_bot/step_walker.py +++ b/pokemongo_bot/step_walker.py @@ -60,6 +60,7 @@ def step(self): cLng = i2f(self.api._position_lng) + scaledDLng + random_lat_long_delta() self.api.set_position(cLat, cLng, 0) + self.bot.position = (cLat,cLng,0) # set position so we can use it later on self.bot.heartbeat() sleep(1) # sleep one second plus a random delta # self._work_at_position(