-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Show Pokestop names #1671
Changes from 1 commit
a8df179
c219bbe
555f213
bfd2931
7f61e87
8f91eef
eba56fb
7d23cd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
from pokemongo_bot.worker_result import WorkerResult | ||
from utils import distance, format_time | ||
|
||
FORT_CACHE = {} | ||
|
||
class SeenFortWorker(object): | ||
def __init__(self, bot): | ||
self.api = bot.api | ||
|
@@ -31,6 +33,16 @@ def work(self): | |
lat = fort['latitude'] | ||
lng = fort['longitude'] | ||
|
||
if getattr(self.bot.config, 'forts_show_name', False) == True: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't put default configuration here, only when we parse the configuration. I also happen to think this should be True by default. |
||
# For user friendliness, restore the old PokeStop names | ||
try: | ||
fort_details = self.get_fort_details(fort['id'], lat, lng) | ||
fort_name = fort_details['name'].encode('utf8', 'replace') | ||
except KeyError: | ||
fort_name = 'Unknown' | ||
|
||
logger.log('Now at Pokestop: {0}'.format(fort_name), 'cyan') | ||
|
||
logger.log('Spinning ...', 'cyan') | ||
|
||
self.api.fort_search(fort_id=fort['id'], | ||
|
@@ -138,3 +150,23 @@ def get_fort_in_range(self): | |
return fort | ||
|
||
return None | ||
|
||
def get_fort_details(self, fort_id, latitude, longitude): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method that does caching probably shouldn't be here. We have more than one place that looks at fort information, so we should save that data and provide a function that everything can use. We should pull this out into init.py, or ideally a new file where we can put methods like this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback. I will work on this further tomorrow. On 29 Jul 2016 18:54, "Eli White" notifications@github.com wrote:
|
||
""" | ||
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. | ||
""" | ||
self.api.fort_details(fort_id=fort_id, latitude=latitude, longitude=longitude) | ||
|
||
try: | ||
response_dict = self.api.call() | ||
FORT_CACHE[fort_id] = response_dict['responses']['FORT_DETAILS'] | ||
except Exception: | ||
pass | ||
|
||
# Just to avoid KeyErrors | ||
return FORT_CACHE.get(fort_id, {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the convention of calling
add_config
to set up this. Check how other parameters that are inside theforts
group are used.