Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/web location file #800

Merged
merged 3 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ If using multiple usernames format like this:
* Leaklessgfy
* codybaldwin
* skyl1ne94
* Heihachi

-------
## Credits
Expand Down
45 changes: 44 additions & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pokemongo_bot/step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down