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

Stale location cache #1932

Merged
merged 2 commits into from
Jul 30, 2016
Merged
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
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