Skip to content

Commit

Permalink
Location cache check. If start position differs, don't use the cache. (
Browse files Browse the repository at this point in the history
  • Loading branch information
cwild authored and elicwhite committed Jul 30, 2016
1 parent 7b3f70f commit 637b7e6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, config):
self.recent_forts = [None] * config.forts_max_circle_size
self.tick_count = 0
self.softban = False
self.start_position = None

# Make our own copy of the workers for this instance
self.workers = []
Expand Down Expand Up @@ -181,7 +182,7 @@ def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
)
try:
with open(user_data_lastlocation, 'w') as outfile:
json.dump({'lat': lat, 'lng': lng}, outfile)
json.dump({'lat': lat, 'lng': lng, 'start_position': self.start_position}, outfile)
except IOError as e:
logger.log('[x] Error while opening location file: %s' % e, 'red')

Expand Down Expand Up @@ -500,6 +501,7 @@ def _set_starting_position(self):
location_str = self.config.location.encode('utf-8')
location = (self.get_pos_by_name(location_str.replace(" ", "")))
self.api.set_position(*location)
self.start_position = self.position
logger.log('')
logger.log(u'Location Found: {}'.format(self.config.location))
logger.log('GeoPosition: {}'.format(self.position))
Expand All @@ -519,7 +521,17 @@ def _set_starting_position(self):
location_json['lng'],
0.0
)
# print(location)

# If location has been set in config, only use cache if starting position has not differed
if has_position and 'start_position' in location_json:
last_start_position = tuple(location_json.get('start_position', []))

# Start position has to have been set on a previous run to do this check
if last_start_position and last_start_position != self.start_position:
logger.log('[x] Last location flag used but with a stale starting location', 'yellow')
logger.log('[x] Using new starting location, {}'.format(self.position))
return

self.api.set_position(*location)

logger.log('')
Expand All @@ -534,7 +546,6 @@ def _set_starting_position(self):
logger.log('')

has_position = True
return
except Exception:
if has_position is False:
sys.exit(
Expand Down

1 comment on commit 637b7e6

@DimaVIII
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THANK YOOOOOU!!!

Please sign in to comment.