mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 12:54:58 +00:00
Dinamically change locale and timezone
During DeviceBuilder initialization, retrieve locale from system using python `locale` module, and set timezone to `Europe/Berlin`. Added some helpers to get and set those values at runtime.
This commit is contained in:
parent
0227cb1cf2
commit
e1acc14424
@ -1,9 +1,10 @@
|
||||
from . import googleplay_pb2
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
from time import time
|
||||
from os import path
|
||||
from sys import version_info
|
||||
from locale import getdefaultlocale
|
||||
|
||||
VERSION = sys.version_info[0]
|
||||
VERSION = version_info[0]
|
||||
if VERSION == 2:
|
||||
import ConfigParser
|
||||
else:
|
||||
@ -11,8 +12,6 @@ else:
|
||||
|
||||
|
||||
DFE_TARGETS = "CAEScFfqlIEG6gUYogFWrAISK1WDAg+hAZoCDgIU1gYEOIACFkLMAeQBnASLATlASUuyAyqCAjY5igOMBQzfA/IClwFbApUC4ANbtgKVAS7OAX8YswHFBhgDwAOPAmGEBt4OfKkB5weSB5AFASkiN68akgMaxAMSAQEBA9kBO7UBFE1KVwIDBGs3go6BBgEBAgMECQgJAQIEAQMEAQMBBQEBBAUEFQYCBgUEAwMBDwIBAgOrARwBEwMEAg0mrwESfTEcAQEKG4EBMxghChMBDwYGASI3hAEODEwXCVh/EREZA4sBYwEdFAgIIwkQcGQRDzQ2fTC2AjfVAQIBAYoBGRg2FhYFBwEqNzACJShzFFblAo0CFxpFNBzaAd0DHjIRI4sBJZcBPdwBCQGhAUd2A7kBLBVPngEECHl0UEUMtQETigHMAgUFCc0BBUUlTywdHDgBiAJ+vgKhAU0uAcYCAWQ/5ALUAw1UwQHUBpIBCdQDhgL4AY4CBQICjARbGFBGWzA1CAEMOQH+BRAOCAZywAIDyQZ2MgM3BxsoAgUEBwcHFia3AgcGTBwHBYwBAlcBggFxSGgIrAEEBw4QEqUCASsWadsHCgUCBQMD7QICA3tXCUw7ugJZAwGyAUwpIwM5AwkDBQMJA5sBCw8BNxBVVBwVKhebARkBAwsQEAgEAhESAgQJEBCZATMdzgEBBwG8AQQYKSMUkAEDAwY/CTs4/wEaAUt1AwEDAQUBAgIEAwYEDx1dB2wGeBFgTQ"
|
||||
LANG = "en_US"
|
||||
TIMEZONE = 'America/New_York'
|
||||
GOOGLE_PUBKEY = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ=="
|
||||
ACCOUNT = "HOSTED_OR_GOOGLE"
|
||||
|
||||
@ -20,7 +19,7 @@ ACCOUNT = "HOSTED_OR_GOOGLE"
|
||||
# if you want to add another phone, just create another section in
|
||||
# the file. Some configurations for common phones can be found here:
|
||||
# https://github.com/yeriomin/play-store-api/tree/master/src/main/resources
|
||||
filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||
filepath = path.join(path.dirname(path.realpath(__file__)),
|
||||
'device.properties')
|
||||
|
||||
if VERSION == 2:
|
||||
@ -49,6 +48,8 @@ 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
|
||||
|
||||
@ -72,10 +73,10 @@ class DeviceBuilder(object):
|
||||
"accountType": ACCOUNT,
|
||||
"has_permission": "1",
|
||||
"source": "android",
|
||||
"device_country": LANG[0:2],
|
||||
"device_country": self.locale[0:2],
|
||||
"service": "androidmarket",
|
||||
"app": "com.android.vending",
|
||||
"lang": LANG,
|
||||
"lang": self.locale,
|
||||
"sdk_version": self.device['build.version.sdk_int']}
|
||||
|
||||
def getLoginParams(self, email, encryptedPass):
|
||||
@ -87,16 +88,16 @@ class DeviceBuilder(object):
|
||||
"has_permission": "1",
|
||||
"app": "com.google.android.gsf",
|
||||
"source": "android",
|
||||
"device_country": LANG[0:2],
|
||||
"lang": LANG,
|
||||
"device_country": self.locale[0:2],
|
||||
"lang": self.locale,
|
||||
"sdk_version": self.device['build.version.sdk_int']}
|
||||
|
||||
def getAndroidCheckinRequest(self):
|
||||
request = googleplay_pb2.AndroidCheckinRequest()
|
||||
request.id = 0
|
||||
request.checkin.CopyFrom(self.getAndroidCheckin())
|
||||
request.locale = LANG
|
||||
request.timeZone = TIMEZONE
|
||||
request.locale = self.locale
|
||||
request.timeZone = self.timezone
|
||||
request.version = 3
|
||||
request.deviceConfiguration.CopyFrom(self.getDeviceConfig())
|
||||
request.fragment = 0
|
||||
@ -148,7 +149,7 @@ class DeviceBuilder(object):
|
||||
androidBuild.buildProduct = self.device['build.product']
|
||||
androidBuild.client = self.device['client']
|
||||
androidBuild.otaInstalled = False
|
||||
androidBuild.timestamp = int(time.time())
|
||||
androidBuild.timestamp = int(time())
|
||||
androidBuild.googleServices = int(self.device['gsf.version'])
|
||||
return androidBuild
|
||||
|
||||
|
@ -84,7 +84,7 @@ class GooglePlayAPI(object):
|
||||
can later be updated, based on the request type"""
|
||||
|
||||
headers = {
|
||||
"Accept-Language": config.LANG.replace('_', '-'),
|
||||
"Accept-Language": self.deviceBuilder.locale.replace('_', '-'),
|
||||
"X-DFE-Encoded-Targets": config.DFE_TARGETS,
|
||||
"User-Agent": self.deviceBuilder.getUserAgent()
|
||||
}
|
||||
@ -420,7 +420,7 @@ class GooglePlayAPI(object):
|
||||
cookies=cookies, verify=ssl_verify,
|
||||
stream=True, timeout=60)
|
||||
total_length = int(response.headers.get('content-length'))
|
||||
chunk_size = 32 * (1<<10) # 32 KB
|
||||
chunk_size = 32 * (1 << 10) # 32 KB
|
||||
bar = progress.Bar(expected_size=(total_length >> 10))
|
||||
for index, chunk in enumerate(response.iter_content(chunk_size=chunk_size)):
|
||||
response_content += chunk
|
||||
@ -536,6 +536,20 @@ class GooglePlayAPI(object):
|
||||
def changeDevice(self, device_codename):
|
||||
self.deviceBuilder = config.DeviceBuilder(device_codename)
|
||||
|
||||
# Helpers
|
||||
|
||||
def getLocale(self):
|
||||
return self.deviceBuilder.locale
|
||||
|
||||
def setLocale(self, locale):
|
||||
self.deviceBuilder.locale = locale
|
||||
|
||||
def getTimeZone(self):
|
||||
return self.deviceBuilder.timezone
|
||||
|
||||
def setTimeZone(self, timezone):
|
||||
self.deviceBuilder.timezone = timezone
|
||||
|
||||
@staticmethod
|
||||
def getDevicesCodenames():
|
||||
return config.getDevicesCodenames()
|
||||
|
Loading…
Reference in New Issue
Block a user