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

Show Pokestop names #1671

Merged
merged 8 commits into from
Jul 30, 2016
23 changes: 23 additions & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,26 @@
from recycle_items_worker import RecycleItemsWorker
from seen_fort_worker import SeenFortWorker
from soft_ban_worker import SoftBanWorker


FORT_CACHE = {}

def fort_details(bot, fort_id, latitude, longitude):
"""
Lookup fort metadata and (if possible) serve from cache.
"""

if fort_id not in FORT_CACHE:
"""
Lookup the fort details and cache the response for future use.
"""
bot.api.fort_details(fort_id=fort_id, latitude=latitude, longitude=longitude)

try:
response_dict = bot.api.call()
FORT_CACHE[fort_id] = response_dict['responses']['FORT_DETAILS']
except Exception:
pass

# Just to avoid KeyErrors
return FORT_CACHE.get(fort_id, {})
9 changes: 3 additions & 6 deletions pokemongo_bot/cell_workers/catch_lured_pokemon_worker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pokemongo_bot import logger
from pokemongo_bot.cell_workers import fort_details
from pokemongo_bot.cell_workers.pokemon_catch_worker import PokemonCatchWorker


Expand All @@ -25,14 +26,10 @@ def get_lured_pokemon(self):
return False

fort = forts[0]

self.api.fort_details(fort_id=fort['id'],
details = fort_details(self.bot, fort_id=fort['id'],
latitude=fort['latitude'],
longitude=fort['longitude'])

response_dict = self.api.call()
fort_details = response_dict.get('responses', {}).get('FORT_DETAILS', {})
fort_name = fort_details.get('name', 'Unknown').encode('utf8', 'replace')
fort_name = details.get('name', 'Unknown').encode('utf8', 'replace')
Copy link
Contributor

Choose a reason for hiding this comment

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

You could probably use this same line in seen_fort_worker. You have a try catch there right now.


encounter_id = fort.get('lure_info', {}).get('encounter_id', None)

Expand Down
5 changes: 4 additions & 1 deletion pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pokemongo_bot.constants import Constants
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.worker_result import WorkerResult
from utils import distance, format_time
from utils import distance, format_time, fort_details


class SeenFortWorker(object):
Expand All @@ -32,6 +32,9 @@ def work(self):
lat = fort['latitude']
lng = fort['longitude']

details = fort_details(self.bot, fort['id'], lat, lng)
fort_name = details.get('name', 'Unknown').encode('utf8', 'replace')
logger.log('Now at Pokestop: {0}'.format(fort_name), 'cyan')
logger.log('Spinning ...', 'cyan')

self.api.fort_search(fort_id=fort['id'],
Expand Down