Skip to content

Commit

Permalink
Merge branch 'dev' into map_synergy
Browse files Browse the repository at this point in the history
* dev:
  Adapt code to new PGoApi Code (PokemonGoF#2357)
  Revert "[Feature] added keep pokemon for batch evolution" (PokemonGoF#2380)
  Revert "Dev Proxy support" (PokemonGoF#2374)
  Supporting sending requests through an HTTP proxy (PokemonGoF#2358)
  [Feature] added keep pokemon for batch evolution (PokemonGoF#2255)
  Fix instance where evolve_all is unicode - fixes PokemonGoF#2281 (PokemonGoF#2305)
  This is just a temp fix, The one added the configure param need make sure it's really work.
  Modify SpiralTask to use 70m as stepsize and diameter as step_count (PokemonGoF#2194)
  web submodule updated to latest commit (PokemonGoF#2289)
  added param in config.json.pokemon.example.
  Add missing curly bracket (PokemonGoF#2282)
  Update web to latest master commit (PokemonGoF#2274)
  Dev - Fixed the loss of fort data (updated) (PokemonGoF#2269)
  Add optional simple lure attraction feature (PokemonGoF#2257)
  [FIX] Improper use of exception  (PokemonGoF#2246)
  Change egg hatching text (PokemonGoF#2258)
  • Loading branch information
mhdasding committed Aug 2, 2016
2 parents f9a92fa + bdf2e7d commit 5fdc2e5
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 223 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@
* mhdasding
* MFizz
* NamPNQ
* z4ppy.bbc
* matheussampaio
* Abraxas000
13 changes: 10 additions & 3 deletions configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@
"type": "SpinFort"
},
{
"type": "MoveToFort"
"type": "MoveToFort",
"config": {
"lure_attraction": true,
"lure_max_distance": 2000
}
},
{
"type": "FollowSpiral"
"type": "FollowSpiral",
"config": {
"diameter": 4,
"step_size": 70
}
}
],
"map_object_cache_time": 5,
"max_steps": 5,
"forts": {
"avoid_circles": true,
"max_circle_size": 50
Expand Down
6 changes: 5 additions & 1 deletion configs/config.json.pokemon.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
"type": "SpinFort"
},
{
"type": "MoveToFort"
"type": "MoveToFort",
"config":{
"lure_attraction": true,
"lure_max_distance": 2000
}
},
{
"type": "FollowSpiral"
Expand Down
12 changes: 1 addition & 11 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,6 @@ def init_config():
type=str,
default=None
)
add_config(
parser,
load,
short_flag="-ms",
long_flag="--max_steps",
help=
"Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)",
type=int,
default=50
)

add_config(
parser,
Expand Down Expand Up @@ -368,7 +358,7 @@ def task_configuration_error(flag_name):
""".format(flag_name))

old_flags = ['mode', 'catch_pokemon', 'spin_forts', 'forts_spin', 'hatch_eggs', 'release_pokemon', 'softban_fix',
'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min']
'longer_eggs_first', 'evolve_speed', 'use_lucky_egg', 'item_filter', 'evolve_all', 'evolve_cp_min', 'max_steps']
for flag in old_flags:
if flag in load:
task_configuration_error(flag)
Expand Down
81 changes: 41 additions & 40 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class PokemonGoBot(object):
def position(self):
return self.api._position_lat, self.api._position_lng, 0

@position.setter
def position(self, position_tuple):
self.api._position_lat, self.api._position_lng, self.api._position_alt = position_tuple

def __init__(self, config):
self.config = config
self.fort_timeouts = dict()
Expand Down Expand Up @@ -104,11 +108,20 @@ def get_meta_cell(self):
if "catchable_pokemons" in cell and len(cell["catchable_pokemons"]):
catchable_pokemons += cell["catchable_pokemons"]

return {
"forts": forts,
"wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons
}
# If there are forts present in the cells sent from the server or we don't yet have any cell data, return all data retrieved
if len(forts) > 1 or not self.cell:
return {
"forts": forts,
"wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons
}
# If there are no forts present in the data from the server, keep our existing fort data and only update the pokemon cells.
else:
return {
"forts": self.cell["forts"],
"wild_pokemons": wild_pokemons,
"catchable_pokemons": catchable_pokemons
}

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
Expand All @@ -121,28 +134,21 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
alt = 0

if cells == []:
cellid = get_cell_ids(lat, lng)
timestamp = [0, ] * len(cellid)
response_dict = self.get_map_objects(lat, lng, timestamp, cellid)
map_objects = response_dict.get(
'responses', {}
).get('GET_MAP_OBJECTS', {})
status = map_objects.get('status', None)
cells = map_objects['map_cells']
location = self.position[0:2]
cells = self.find_close_cells(*location)

# insert detail info about gym to fort
for cell in cells:
if 'forts' in cell:
for fort in cell['forts']:
if fort.get('type') != 1:
self.api.get_gym_details(
response_gym_details = self.api.get_gym_details(
gym_id=fort.get('id'),
player_latitude=lng,
player_longitude=lat,
gym_latitude=fort.get('latitude'),
gym_longitude=fort.get('longitude')
)
response_gym_details = self.api.call()
fort['gym_details'] = response_gym_details.get(
'responses', {}
).get('GET_GYM_DETAILS', None)
Expand Down Expand Up @@ -236,6 +242,9 @@ def check_session(self, position):

if remaining_time < 60:
logger.log("Session stale, re-logging in", 'yellow')
position = self.position
self.api = ApiWrapper()
self.position = position
self.login()

@staticmethod
Expand All @@ -248,13 +257,13 @@ def is_numeric(s):

def login(self):
logger.log('Attempting login to Pokemon Go.', 'white')
self.api.reset_auth()
lat, lng = self.position[0:2]
self.api.set_position(lat, lng, 0)

while not self.api.login(self.config.auth_service,
str(self.config.username),
str(self.config.password)):
while not self.api.login(
self.config.auth_service,
str(self.config.username),
str(self.config.password)):

logger.log('[X] Login Error, server busy', 'red')
logger.log('[X] Waiting 10 seconds to try again', 'red')
Expand All @@ -264,7 +273,7 @@ def login(self):

def _setup_api(self):
# instantiate pgoapi
self.api = ApiWrapper(PGoApi())
self.api = ApiWrapper()

# provide player position on the earth
self._set_starting_position()
Expand All @@ -283,8 +292,7 @@ def _setup_api(self):
def _print_character_info(self):
# get player profile call
# ----------------------
self.api.get_player()
response_dict = self.api.call()
response_dict = self.api.get_player()
# print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2)))
currency_1 = "0"
currency_2 = "0"
Expand Down Expand Up @@ -365,15 +373,11 @@ def _print_character_info(self):
logger.log('')

def use_lucky_egg(self):
self.api.use_item_xp_boost(item_id=301)
inventory_req = self.api.call()
return inventory_req
return self.api.use_item_xp_boost(item_id=301)

def get_inventory(self):
if self.latest_inventory is None:
self.api.get_inventory()
response = self.api.call()
self.latest_inventory = response
self.latest_inventory = self.api.get_inventory()
return self.latest_inventory

def update_inventory(self):
Expand Down Expand Up @@ -402,15 +406,13 @@ def current_inventory(self):
items_stock = {x.value: 0 for x in list(Item)}

for item in inventory_dict:
try:
# print(item['inventory_item_data']['item'])
item_id = item['inventory_item_data']['item']['item_id']
item_count = item['inventory_item_data']['item']['count']
item_dict = item.get('inventory_item_data', {}).get('item', {})
item_count = item_dict.get('count')
item_id = item_dict.get('item_id')

if item_count and item_id:
if item_id in items_stock:
items_stock[item_id] = item_count
except Exception:
continue
return items_stock

def item_inventory_count(self, id):
Expand Down Expand Up @@ -538,9 +540,10 @@ def heartbeat(self):
self.fort_timeouts = {id: timeout for id, timeout
in self.fort_timeouts.iteritems()
if timeout >= time.time() * 1000}
self.api.get_player()
self.api.check_awarded_badges()
self.api.call()
request = self.api.create_request()
request.get_player()
request.check_awarded_badges()
request.call()
self.update_web_location() # updates every tick

def get_inventory_count(self, what):
Expand Down Expand Up @@ -620,14 +623,12 @@ def get_map_objects(self, lat, lng, timestamp, cellid):
if time.time() - self.last_time_map_object < self.config.map_object_cache_time:
return self.last_map_object

self.api.get_map_objects(
self.last_map_object = self.api.get_map_objects(
latitude=f2i(lat),
longitude=f2i(lng),
since_timestamp_ms=timestamp,
cell_id=cellid
)

self.last_map_object = self.api.call()
self.last_time_map_object = time.time()

return self.last_map_object
Loading

0 comments on commit 5fdc2e5

Please sign in to comment.