Changed Locale and TimeZone initialization

Before, if locale wasn't specified as a parameter, it was picked from
the system running gpapi. Similar thing happened for timezone, but its
value was hardcoded in config.py.
To avoid problems related to missing or unavailable apps, this commit
enforces users to provide a locale and a timezone value. Without them,
gpapi can't be initialized.
This commit is contained in:
Domenico Iezzi 2018-01-25 11:36:25 +01:00
parent d7a322dd82
commit 24a3e1a09b
No known key found for this signature in database
GPG Key ID: 7AC94D5DDA2FB7EE
3 changed files with 26 additions and 29 deletions

View File

@ -2,7 +2,6 @@ from . import googleplay_pb2
from time import time
from os import path
from sys import version_info
from locale import getdefaultlocale
from re import match
VERSION = version_info[0]
@ -37,50 +36,53 @@ def getDevicesCodenames():
def getDevicesReadableNames():
"""Returns codename and readable name for each device"""
sections = getDevicesCodenames()
output = []
for s in sections:
output.append({'codename': s,
'readableName': config[s]['userreadablename']})
return output
return [{'codename': s,
'readableName': config.get(s).get('userreadablename')}
for s in getDevicesCodenames()]
class DeviceBuilder(object):
def __init__(self, device):
self.device = {}
self.timezone = "Europe/Berlin"
for (key, value) in config.items(device):
self.device[key] = value
def setLocale(self, locale):
# test if provided locale is valid
if locale is None or type(locale) is not str:
# try to fetch it from system
locale = getdefaultlocale()[0]
# getdefaultlocale may return None, we need another check
if locale is None:
locale = ''
raise Exception('Wrong locale supplied')
# 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'
raise Exception('Wrong locale supplied')
self.locale = locale
def set_timezone(self, timezone):
if timezone is None or type(timezone) is not str:
timezone = self.device.get('timezone')
if timezone is None:
raise Exception('Wrong timezone supplied')
self.timezone = timezone
def getUserAgent(self):
return ("Android-Finsky/8.1.72.S-all [6] [PR] 165478484 ("
version_string = self.device.get('vending.versionstring')
if version_string is None:
version_string = '8.4.19.V-all [0] [FP] 175058788'
return ("Android-Finsky/{versionString} ("
"api=3"
",versionCode={versionCode}"
",sdk={sdk}"
",device={device}"
",hardware={hardware}"
",product={product}"
"").format(versionCode=self.device['vending.version'],
sdk=self.device['build.version.sdk_int'],
device=self.device['build.device'],
hardware=self.device['build.hardware'],
product=self.device['build.product'])
"").format(versionString=version_string,
versionCode=self.device.get('vending.version'),
sdk=self.device.get('build.version.sdk_int'),
device=self.device.get('build.device'),
hardware=self.device.get('build.hardware'),
product=self.device.get('build.product'))
def getAuthParams(self, email, passwd):
return {"Email": email,

View File

@ -49,7 +49,6 @@ class GooglePlayAPI(object):
def __init__(self, debug=False, device_codename='bacon',
locale=None, timezone=None,
sim_operator=None, cell_operator=None,
proxies_config=None):
self.authSubToken = None
self.gsfId = None
@ -57,12 +56,7 @@ class GooglePlayAPI(object):
self.proxies_config = proxies_config
self.deviceBuilder = config.DeviceBuilder(device_codename)
self.deviceBuilder.setLocale(locale)
if timezone is not None:
self.deviceBuilder.timezone = timezone
if sim_operator is not None:
self.deviceBuilder.device['simoperator'] = sim_operator
if cell_operator is not None:
self.deviceBuilder.device['celloperator'] = cell_operator
self.deviceBuilder.set_timezone(timezone)
def encrypt_password(self, login, passwd):
"""Encrypt the password using the google publickey, using
@ -489,6 +483,7 @@ class GooglePlayAPI(object):
if not progress_bar:
return requests.get(url, headers=headers,
cookies=cookies, verify=ssl_verify,
stream=True,
timeout=60,
proxies=self.proxies_config).content
response_content = bytes()

View File

@ -9,7 +9,7 @@ ap.add_argument('-p', '--password', dest='password', help='google password')
args = ap.parse_args()
server = GooglePlayAPI(debug=True)
server = GooglePlayAPI(debug=True, locale='it_IT')
# LOGIN
@ -19,7 +19,7 @@ gsfId = server.gsfId
authSubToken = server.authSubToken
print('\nNow trying secondary login with ac2dm token and gsfId saved\n')
server = GooglePlayAPI(debug=True)
server = GooglePlayAPI(debug=True, locale='it_IT')
server.login(None, None, gsfId, authSubToken)
# SEARCH