Skip to content

Commit

Permalink
Fix #22
Browse files Browse the repository at this point in the history
Now gpapi checks if the locale retrieved from system or provided by the
user is valid. In case it's invalid, default to en_US.
  • Loading branch information
Domenico Iezzi committed Nov 13, 2017
1 parent ac2d07a commit c61819d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 11 additions & 1 deletion gpapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from os import path
from sys import version_info
from locale import getdefaultlocale
from re import match

VERSION = version_info[0]
if VERSION == 2:
Expand Down Expand Up @@ -48,11 +49,20 @@ class DeviceBuilder(object):

def __init__(self, device):
self.device = {}
self.locale = getdefaultlocale()[0]
self.timezone = "Europe/Berlin"
for (key, value) in config.items(device):
self.device[key] = value

def setLocale(self, locale):
if locale is None:
locale = getdefaultlocale()[0]

# check if locale matches the structure of a common
# value like "en_US"
if match(r'[a-z]{2}\_[A-Z]{2}', locale) is None:
locale = 'en_US'
self.locale = locale

def getUserAgent(self):
return ("Android-Finsky/8.1.72.S-all [6] [PR] 165478484 ("
"api=3"
Expand Down
3 changes: 1 addition & 2 deletions gpapi/googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def __init__(self, debug=False, device_codename='bacon',
self.gsfId = None
self.debug = debug
self.deviceBuilder = config.DeviceBuilder(device_codename)
if locale is not None:
self.deviceBuilder.locale = locale
self.deviceBuilder.setLocale(locale)
if timezone is not None:
self.deviceBuilder.timezone = timezone
if sim_operator is not None:
Expand Down

0 comments on commit c61819d

Please sign in to comment.