From c52245ad44920854d3f99f6d81be0665aa686e17 Mon Sep 17 00:00:00 2001 From: Heihachi Date: Mon, 25 Jul 2016 07:08:13 -0400 Subject: [PATCH 1/3] Attempting to add location-%.json back to bot for web --- pokemongo_bot/__init__.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index e9c2c9ee4b..8263b19376 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -41,6 +41,19 @@ def take_step(self): for cell in cells: self.work_on_cell(cell, location) + def update_web_location(self, cells, lat, lng, alt=0): + logger.log("Updating web location!","blue") + 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) + def find_close_cells(self, lat, lng): cellid = get_cellid(lat, lng) timestamp = [0, ] * len(cellid) @@ -66,6 +79,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 +290,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 +341,7 @@ def update_inventory(self): continue self.inventory.append(item['inventory_item_data'][ 'item']) - + def pokeball_inventory(self): self.api.get_player().get_inventory() From 31a69e24578e2da3684a53d101fa4148826a00da Mon Sep 17 00:00:00 2001 From: Heihachi Date: Mon, 25 Jul 2016 08:12:21 -0400 Subject: [PATCH 2/3] Web Map should track bots now. --- pokemongo_bot/__init__.py | 28 +++++++++++++++++++++++++--- pokemongo_bot/step_walker.py | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py index 8263b19376..6090d2ac1a 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -41,11 +41,32 @@ def take_step(self): for cell in cells: self.work_on_cell(cell, location) - def update_web_location(self, cells, lat, lng, alt=0): - logger.log("Updating web location!","blue") + 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 + # alt is unused atm but makes using *location easier with open(user_web_location,'w') as outfile: json.dump( {'lat': lat, @@ -511,6 +532,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( From 125faf3fe072e2a66dc5d8e213449895526482ee Mon Sep 17 00:00:00 2001 From: Heihachi Date: Mon, 25 Jul 2016 08:45:25 -0400 Subject: [PATCH 3/3] Added data/last-location-%username%.json as well --- README.md | 1 + pokemongo_bot/__init__.py | 5 +++++ 2 files changed, 6 insertions(+) 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 6090d2ac1a..b6b9bd9e7b 100644 --- a/pokemongo_bot/__init__.py +++ b/pokemongo_bot/__init__.py @@ -75,6 +75,11 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None): '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)