Skip to content

Commit

Permalink
Merge pull request #6187 from MerlionRock/locale-by-location
Browse files Browse the repository at this point in the history
Locale by location
  • Loading branch information
Jcolomar authored Aug 3, 2017
2 parents 47d4aa8 + 694222c commit e935beb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
3 changes: 2 additions & 1 deletion configs/auth.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"coords": "45.472849,9.177567"
}
],
"gmapkey": "GOOGLE_MAPS_API_KEY",
"gmapkey": "GOOGLE_MAPS_API_KEY",
"locale_by_location": false,
"hashkey" : "YOUR_PURCHASED_HASH_KEY",
"telegram_token": "",
"discord_token": "",
Expand Down
11 changes: 9 additions & 2 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ Document the configuration options of PokemonGo-Bot.
3. copy `config.json.example` to `config.json`.=
3. Simply launch the script with : `./run.sh` or './run.sh ./configs/your_auth_file.json ./configs/your_base_config_file.json'

### About locale\_by\_location
[[back to top](#table-of-contents)]

By default the bot will tell game server that current timezone is `"America/Chicago"`. By seting `locale_by_location` to `true`, the bot will use google API to determine Country Code and Timezone base on bot's location and send this information to game server.

Please make sure you have both Google Maps Geocoding API and Google Maps Time Zone API enabled in [Google API Manager] (https://console.developers.google.com/) if you want to set this option to true.

## Advanced Configuration
[[back to top](#table-of-contents)]
Expand Down Expand Up @@ -173,6 +179,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`

### Task Options:
[[back to top](#table-of-contents)]

* CatchPokemon
* `enabled`: Default "true" | Enable/Disable the task.
* `always_catch_family_of_vip`: Default "false" | Always catch family members of a VIP, even if locked on a target.
Expand Down Expand Up @@ -297,7 +304,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`

### Specify a custom log_interval for specific task

```
```
{
"type": "MoveToFort",
"config": {
Expand All @@ -308,7 +315,7 @@ The behaviors of the bot are configured via the `tasks` key in the `config.json`
"log_interval": 5
}
}
```
```

Result:

Expand Down
8 changes: 8 additions & 0 deletions pokecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@ def _json_loader(filename):
help="hashendpoint",
default=None
)
add_config(
parser,
load,
short_flag="-ll",
long_flag="--locale_by_location",
help="Set locale information base on bot location",
default=False
)
add_config(
parser,
load,
Expand Down
39 changes: 35 additions & 4 deletions pokemongo_bot/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from pgoapi.exceptions import (ServerSideRequestThrottlingException,
NotLoggedInException, ServerBusyOrOfflineException,
NoPlayerPositionSetException, HashingOfflineException,
UnexpectedResponseException, BadHashRequestException)
UnexpectedResponseException, BadHashRequestException, BannedAccountException)
from pgoapi.pgoapi import PGoApi
from pgoapi.pgoapi import PGoApiRequest
from pgoapi.pgoapi import RpcApi
from pgoapi.protos.pogoprotos.networking.requests.request_type_pb2 import RequestType
from pgoapi.utilities import get_time
from .human_behaviour import sleep, gps_noise_rng
from pokemongo_bot.base_dir import _base_dir

from geopy.geocoders import GoogleV3

class PermaBannedException(Exception):
pass
Expand All @@ -43,6 +43,7 @@ def __init__(self, config=None):
}

PGoApi.__init__(self, device_info=device_info)

if not self.config.hashkey is None:
PGoApi.activate_hash_server(self,self.config.hashkey)
# Set to default, just for CI...
Expand Down Expand Up @@ -91,11 +92,34 @@ def create_request(self):
self._position_lng,
self._position_alt
)

def get_component(self, location, component_type):
for component in location.raw['address_components']:
if component_type in component['types']:
return component['short_name']

def login(self, provider, username, password):
# login needs base class "create_request"
self.useVanillaRequest = True

# Get Timecode and Country Code
country_code = "US"
timezone = "America/Chicago"
geolocator = GoogleV3(api_key=self.config.gmapkey)

if self.config.locale_by_location:
try:
location = geolocator.reverse((self.actual_lat, self.actual_lng), timeout = 10, exactly_one=True)
country_code = self.get_component(location,'country')
except:
self.logger.warning("Please make sure you have google api key and enable Google Maps Geocoding API at console.developers.google.com")

try:
timezone = geolocator.timezone([self.actual_lat, self.actual_lng], timeout=10)
except:
self.logger.warning("Please make sure you have google api key and enable Google Maps Time Zone API at console.developers.google.com")

# Start login process
try:
PGoApi.set_authentication(
self,
Expand All @@ -106,12 +130,19 @@ def login(self, provider, username, password):
except:
raise
try:
response = PGoApi.app_simulation_login(self)
if self.config.locale_by_location:
response = PGoApi.app_simulation_login(self,country_code,timezone.zone)
else:
response = PGoApi.app_simulation_login(self) # To prevent user who have not update the api being caught off guard by errors
except BadHashRequestException:
self.logger.warning("You hashkey seems to have expired or is not accepted!")
self.logger.warning("Your hashkey seems to have expired or is not accepted!")
self.logger.warning("Please set a valid hash key in your auth JSON file!")
exit(-3)
raise
except BannedAccountException:
self.logger.warning("This account is banned!")
exit(-3)
raise
except:
raise
# cleanup code
Expand Down

0 comments on commit e935beb

Please sign in to comment.