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
3 changes: 2 additions & 1 deletion configs/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"forts": {
"spin": true,
"avoid_circles": true,
"max_circle_size": 50
"max_circle_size": 50,
"show_name": false
},
"websocket_server": false,
"walk": 4.16,
Expand Down
2 changes: 2 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ def init_config():
config.hatch_eggs = load.get("hatch_eggs", True)
config.longer_eggs_first = load.get("longer_eggs_first", True)

config.forts_show_name = load.get('forts', {}).get('show_name', False)
Copy link
Member

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 the forts group are used.


if config.auth_service not in ['ptc', 'google']:
logging.error("Invalid Auth service specified! ('ptc' or 'google')")
return None
Expand Down
32 changes: 32 additions & 0 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +33,16 @@ def work(self):
lat = fort['latitude']
lng = fort['longitude']

if getattr(self.bot.config, 'forts_show_name', False) == True:
Copy link
Contributor

Choose a reason for hiding this comment

The 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'],
Expand Down Expand Up @@ -138,3 +150,23 @@ def get_fort_in_range(self):
return fort

return None

def get_fort_details(self, fort_id, latitude, longitude):
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:

In pokemongo_bot/cell_workers/seen_fort_worker.py
#1671 (comment)
:

@@ -138,3 +150,23 @@ def get_fort_in_range(self):
return fort

     return None
  • def get_fort_details(self, fort_id, latitude, longitude):

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.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/PokemonGoF/PokemonGo-Bot/pull/1671/files/a8df1799bd46d1df9789666fef34d27ce4feac99#r72833653,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABg2CJjJNC5LdtsfBi8IydD6poJGw-t2ks5qaj5QgaJpZM4JYaNI
.

"""
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, {})