Skip to content

Commit

Permalink
Show Pokestop names (#1671)
Browse files Browse the repository at this point in the history
* Restore the ability for a user to see Pokestop names. Default to off.

* Use the add_config function for forts.show_name (now default to true)

* Move fort_details function into cell_workers init module

* Forgot to pass bot reference

* Catching lured pokemon should use same fort_details API

* REmove config option. Always show Pokestop name.

* Move away from KeyError handling as per TheSaviour's suggestion
  • Loading branch information
cwild authored and douglascamata committed Jul 30, 2016
1 parent 6562af0 commit 1430575
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
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')

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

1 comment on commit 1430575

@DisasteR
Copy link

Choose a reason for hiding this comment

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

Wiki and config example not updated.

Please sign in to comment.