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
|
from . import googleplay_pb2
|
||||||
import time
|
from time import time
|
||||||
import os
|
from os import path
|
||||||
import sys
|
from sys import version_info
|
||||||
|
from locale import getdefaultlocale
|
||||||
|
|
||||||
VERSION = sys.version_info[0]
|
VERSION = version_info[0]
|
||||||
if VERSION == 2:
|
if VERSION == 2:
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
else:
|
else:
|
||||||
@ -11,8 +12,6 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
DFE_TARGETS = "CAEScFfqlIEG6gUYogFWrAISK1WDAg+hAZoCDgIU1gYEOIACFkLMAeQBnASLATlASUuyAyqCAjY5igOMBQzfA/IClwFbApUC4ANbtgKVAS7OAX8YswHFBhgDwAOPAmGEBt4OfKkB5weSB5AFASkiN68akgMaxAMSAQEBA9kBO7UBFE1KVwIDBGs3go6BBgEBAgMECQgJAQIEAQMEAQMBBQEBBAUEFQYCBgUEAwMBDwIBAgOrARwBEwMEAg0mrwESfTEcAQEKG4EBMxghChMBDwYGASI3hAEODEwXCVh/EREZA4sBYwEdFAgIIwkQcGQRDzQ2fTC2AjfVAQIBAYoBGRg2FhYFBwEqNzACJShzFFblAo0CFxpFNBzaAd0DHjIRI4sBJZcBPdwBCQGhAUd2A7kBLBVPngEECHl0UEUMtQETigHMAgUFCc0BBUUlTywdHDgBiAJ+vgKhAU0uAcYCAWQ/5ALUAw1UwQHUBpIBCdQDhgL4AY4CBQICjARbGFBGWzA1CAEMOQH+BRAOCAZywAIDyQZ2MgM3BxsoAgUEBwcHFia3AgcGTBwHBYwBAlcBggFxSGgIrAEEBw4QEqUCASsWadsHCgUCBQMD7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XcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ=="
|
GOOGLE_PUBKEY = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6prwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ=="
|
||||||
ACCOUNT = "HOSTED_OR_GOOGLE"
|
ACCOUNT = "HOSTED_OR_GOOGLE"
|
||||||
|
|
||||||
@ -20,7 +19,7 @@ ACCOUNT = "HOSTED_OR_GOOGLE"
|
|||||||
# if you want to add another phone, just create another section in
|
# if you want to add another phone, just create another section in
|
||||||
# the file. Some configurations for common phones can be found here:
|
# the file. Some configurations for common phones can be found here:
|
||||||
# https://github.com/yeriomin/play-store-api/tree/master/src/main/resources
|
# 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')
|
'device.properties')
|
||||||
|
|
||||||
if VERSION == 2:
|
if VERSION == 2:
|
||||||
@ -49,6 +48,8 @@ class DeviceBuilder(object):
|
|||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
self.device = {}
|
self.device = {}
|
||||||
|
self.locale = getdefaultlocale()[0]
|
||||||
|
self.timezone = "Europe/Berlin"
|
||||||
for (key, value) in config.items(device):
|
for (key, value) in config.items(device):
|
||||||
self.device[key] = value
|
self.device[key] = value
|
||||||
|
|
||||||
@ -72,10 +73,10 @@ class DeviceBuilder(object):
|
|||||||
"accountType": ACCOUNT,
|
"accountType": ACCOUNT,
|
||||||
"has_permission": "1",
|
"has_permission": "1",
|
||||||
"source": "android",
|
"source": "android",
|
||||||
"device_country": LANG[0:2],
|
"device_country": self.locale[0:2],
|
||||||
"service": "androidmarket",
|
"service": "androidmarket",
|
||||||
"app": "com.android.vending",
|
"app": "com.android.vending",
|
||||||
"lang": LANG,
|
"lang": self.locale,
|
||||||
"sdk_version": self.device['build.version.sdk_int']}
|
"sdk_version": self.device['build.version.sdk_int']}
|
||||||
|
|
||||||
def getLoginParams(self, email, encryptedPass):
|
def getLoginParams(self, email, encryptedPass):
|
||||||
@ -87,16 +88,16 @@ class DeviceBuilder(object):
|
|||||||
"has_permission": "1",
|
"has_permission": "1",
|
||||||
"app": "com.google.android.gsf",
|
"app": "com.google.android.gsf",
|
||||||
"source": "android",
|
"source": "android",
|
||||||
"device_country": LANG[0:2],
|
"device_country": self.locale[0:2],
|
||||||
"lang": LANG,
|
"lang": self.locale,
|
||||||
"sdk_version": self.device['build.version.sdk_int']}
|
"sdk_version": self.device['build.version.sdk_int']}
|
||||||
|
|
||||||
def getAndroidCheckinRequest(self):
|
def getAndroidCheckinRequest(self):
|
||||||
request = googleplay_pb2.AndroidCheckinRequest()
|
request = googleplay_pb2.AndroidCheckinRequest()
|
||||||
request.id = 0
|
request.id = 0
|
||||||
request.checkin.CopyFrom(self.getAndroidCheckin())
|
request.checkin.CopyFrom(self.getAndroidCheckin())
|
||||||
request.locale = LANG
|
request.locale = self.locale
|
||||||
request.timeZone = TIMEZONE
|
request.timeZone = self.timezone
|
||||||
request.version = 3
|
request.version = 3
|
||||||
request.deviceConfiguration.CopyFrom(self.getDeviceConfig())
|
request.deviceConfiguration.CopyFrom(self.getDeviceConfig())
|
||||||
request.fragment = 0
|
request.fragment = 0
|
||||||
@ -148,7 +149,7 @@ class DeviceBuilder(object):
|
|||||||
androidBuild.buildProduct = self.device['build.product']
|
androidBuild.buildProduct = self.device['build.product']
|
||||||
androidBuild.client = self.device['client']
|
androidBuild.client = self.device['client']
|
||||||
androidBuild.otaInstalled = False
|
androidBuild.otaInstalled = False
|
||||||
androidBuild.timestamp = int(time.time())
|
androidBuild.timestamp = int(time())
|
||||||
androidBuild.googleServices = int(self.device['gsf.version'])
|
androidBuild.googleServices = int(self.device['gsf.version'])
|
||||||
return androidBuild
|
return androidBuild
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ class GooglePlayAPI(object):
|
|||||||
can later be updated, based on the request type"""
|
can later be updated, based on the request type"""
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Accept-Language": config.LANG.replace('_', '-'),
|
"Accept-Language": self.deviceBuilder.locale.replace('_', '-'),
|
||||||
"X-DFE-Encoded-Targets": config.DFE_TARGETS,
|
"X-DFE-Encoded-Targets": config.DFE_TARGETS,
|
||||||
"User-Agent": self.deviceBuilder.getUserAgent()
|
"User-Agent": self.deviceBuilder.getUserAgent()
|
||||||
}
|
}
|
||||||
@ -536,6 +536,20 @@ class GooglePlayAPI(object):
|
|||||||
def changeDevice(self, device_codename):
|
def changeDevice(self, device_codename):
|
||||||
self.deviceBuilder = config.DeviceBuilder(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
|
@staticmethod
|
||||||
def getDevicesCodenames():
|
def getDevicesCodenames():
|
||||||
return config.getDevicesCodenames()
|
return config.getDevicesCodenames()
|
||||||
|
Loading…
Reference in New Issue
Block a user