mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 04:44:59 +00:00
Fix #22
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.
This commit is contained in:
parent
ac2d07a8c9
commit
c61819d00b
@ -3,6 +3,7 @@ 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]
|
||||
if VERSION == 2:
|
||||
@ -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"
|
||||
|
@ -52,8 +52,7 @@ class GooglePlayAPI(object):
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user