mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 12:54:58 +00:00
Code style improvements, checked using flake8
Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
parent
313d6075e0
commit
3b37b18542
@ -24,13 +24,16 @@ if VERSION == 2:
|
|||||||
else:
|
else:
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
||||||
filepath = os.path.join( os.path.dirname( os.path.realpath(__file__) ), 'device.properties')
|
filepath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
'device.properties')
|
||||||
config.read(filepath)
|
config.read(filepath)
|
||||||
device = {}
|
device = {}
|
||||||
|
|
||||||
|
|
||||||
def getDevicesCodenames():
|
def getDevicesCodenames():
|
||||||
return config.sections()
|
return config.sections()
|
||||||
|
|
||||||
|
|
||||||
def getDeviceConfig():
|
def getDeviceConfig():
|
||||||
libList = device['sharedlibraries'].split(",")
|
libList = device['sharedlibraries'].split(",")
|
||||||
featureList = device['features'].split(",")
|
featureList = device['features'].split(",")
|
||||||
@ -61,6 +64,7 @@ def getDeviceConfig():
|
|||||||
deviceConfig.glExtension.append(x)
|
deviceConfig.glExtension.append(x)
|
||||||
return deviceConfig
|
return deviceConfig
|
||||||
|
|
||||||
|
|
||||||
def getAndroidBuild():
|
def getAndroidBuild():
|
||||||
androidBuild = googleplay_pb2.AndroidBuildProto()
|
androidBuild = googleplay_pb2.AndroidBuildProto()
|
||||||
androidBuild.id = device['build.fingerprint']
|
androidBuild.id = device['build.fingerprint']
|
||||||
@ -79,6 +83,7 @@ def getAndroidBuild():
|
|||||||
androidBuild.googleServices = int(device['gsf.version'])
|
androidBuild.googleServices = int(device['gsf.version'])
|
||||||
return androidBuild
|
return androidBuild
|
||||||
|
|
||||||
|
|
||||||
def getAndroidCheckin():
|
def getAndroidCheckin():
|
||||||
androidCheckin = googleplay_pb2.AndroidCheckinProto()
|
androidCheckin = googleplay_pb2.AndroidCheckinProto()
|
||||||
androidCheckin.build.CopyFrom(getAndroidBuild())
|
androidCheckin.build.CopyFrom(getAndroidBuild())
|
||||||
@ -89,6 +94,7 @@ def getAndroidCheckin():
|
|||||||
androidCheckin.userNumber = 0
|
androidCheckin.userNumber = 0
|
||||||
return androidCheckin
|
return androidCheckin
|
||||||
|
|
||||||
|
|
||||||
def getAndroidCheckinRequest(device_codename):
|
def getAndroidCheckinRequest(device_codename):
|
||||||
for (key, value) in config.items(device_codename):
|
for (key, value) in config.items(device_codename):
|
||||||
device[key] = value
|
device[key] = value
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
|
||||||
from google.protobuf import descriptor
|
|
||||||
from google.protobuf.internal.containers import RepeatedCompositeFieldContainer
|
|
||||||
from google.protobuf import text_format
|
|
||||||
from google.protobuf.message import Message
|
|
||||||
from Crypto.Util import asn1
|
from Crypto.Util import asn1
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from Crypto.Hash import SHA
|
from Crypto.Hash import SHA
|
||||||
@ -13,7 +9,6 @@ from clint.textui import progress
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
import base64
|
import base64
|
||||||
import struct
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from . import googleplay_pb2, config, utils
|
from . import googleplay_pb2, config, utils
|
||||||
@ -116,8 +111,6 @@ class GooglePlayAPI(object):
|
|||||||
response = googleplay_pb2.AndroidCheckinResponse()
|
response = googleplay_pb2.AndroidCheckinResponse()
|
||||||
response.ParseFromString(res.content)
|
response.ParseFromString(res.content)
|
||||||
|
|
||||||
securityToken = "{0:x}".format(response.securityToken)
|
|
||||||
|
|
||||||
# checkin again to upload gfsid
|
# checkin again to upload gfsid
|
||||||
request2 = googleplay_pb2.AndroidCheckinRequest()
|
request2 = googleplay_pb2.AndroidCheckinRequest()
|
||||||
request2.CopyFrom(request)
|
request2.CopyFrom(request)
|
||||||
@ -126,7 +119,7 @@ class GooglePlayAPI(object):
|
|||||||
request2.accountCookie.append("[" + email + "]")
|
request2.accountCookie.append("[" + email + "]")
|
||||||
request2.accountCookie.append(ac2dmToken)
|
request2.accountCookie.append(ac2dmToken)
|
||||||
stringRequest = request2.SerializeToString()
|
stringRequest = request2.SerializeToString()
|
||||||
res2 = requests.post(self.CHECKINURL, data=stringRequest,
|
requests.post(self.CHECKINURL, data=stringRequest,
|
||||||
headers=headers, verify=ssl_verify)
|
headers=headers, verify=ssl_verify)
|
||||||
|
|
||||||
return response.androidId
|
return response.androidId
|
||||||
@ -146,8 +139,7 @@ class GooglePlayAPI(object):
|
|||||||
stringRequest = upload.SerializeToString()
|
stringRequest = upload.SerializeToString()
|
||||||
res = requests.post(self.UPLOADURL, data=stringRequest,
|
res = requests.post(self.UPLOADURL, data=stringRequest,
|
||||||
headers=headers, verify=ssl_verify)
|
headers=headers, verify=ssl_verify)
|
||||||
response = googleplay_pb2.ResponseWrapper.FromString(res.content)
|
googleplay_pb2.ResponseWrapper.FromString(res.content)
|
||||||
|
|
||||||
|
|
||||||
def login(self, email=None, password=None, gsfId=None, authSubToken=None, device_codename='angler'):
|
def login(self, email=None, password=None, gsfId=None, authSubToken=None, device_codename='angler'):
|
||||||
"""Login to your Google Account.
|
"""Login to your Google Account.
|
||||||
@ -239,7 +231,7 @@ class GooglePlayAPI(object):
|
|||||||
|
|
||||||
def executeRequestApi2(self, path, datapost=None,
|
def executeRequestApi2(self, path, datapost=None,
|
||||||
post_content_type="application/x-www-form-urlencoded; charset=UTF-8"):
|
post_content_type="application/x-www-form-urlencoded; charset=UTF-8"):
|
||||||
if self.authSubToken == None:
|
if self.authSubToken is None:
|
||||||
raise Exception("You need to login before executing any request")
|
raise Exception("You need to login before executing any request")
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getDefaultHeaders()
|
||||||
|
|
||||||
@ -267,7 +259,7 @@ class GooglePlayAPI(object):
|
|||||||
|
|
||||||
offset is used to take result starting from an index.
|
offset is used to take result starting from an index.
|
||||||
"""
|
"""
|
||||||
if self.authSubToken == None:
|
if self.authSubToken is None:
|
||||||
raise Exception("You need to login before executing any request")
|
raise Exception("You need to login before executing any request")
|
||||||
|
|
||||||
remaining = nb_result
|
remaining = nb_result
|
||||||
@ -276,7 +268,7 @@ class GooglePlayAPI(object):
|
|||||||
nextPath = "search?c=3&q=%s" % requests.utils.quote(query)
|
nextPath = "search?c=3&q=%s" % requests.utils.quote(query)
|
||||||
if (offset is not None):
|
if (offset is not None):
|
||||||
nextPath += "&o=%d" % int(offset)
|
nextPath += "&o=%d" % int(offset)
|
||||||
while remaining > 0 and nextPath != None:
|
while remaining > 0 and nextPath is not None:
|
||||||
currentPath = nextPath
|
currentPath = nextPath
|
||||||
data = self.executeRequestApi2(currentPath)
|
data = self.executeRequestApi2(currentPath)
|
||||||
if len(data.preFetch) > 0:
|
if len(data.preFetch) > 0:
|
||||||
@ -357,12 +349,13 @@ class GooglePlayAPI(object):
|
|||||||
for pf in data.preFetch:
|
for pf in data.preFetch:
|
||||||
for cluster in pf.response.payload.listResponse.cluster:
|
for cluster in pf.response.payload.listResponse.cluster:
|
||||||
for doc in cluster.doc:
|
for doc in cluster.doc:
|
||||||
|
apps = [a for a in doc.child]
|
||||||
|
apps = list(map(utils.fromDocToDictionary,
|
||||||
|
apps))
|
||||||
section = {'title': doc.title,
|
section = {'title': doc.title,
|
||||||
'docid': doc.docid,
|
'docid': doc.docid,
|
||||||
'apps': list(map(utils.fromDocToDictionary,
|
'apps': apps}
|
||||||
[a for a in doc.child])) }
|
|
||||||
output.append(section)
|
output.append(section)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def list(self, cat, ctr=None, nb_results=None, offset=None):
|
def list(self, cat, ctr=None, nb_results=None, offset=None):
|
||||||
@ -390,9 +383,10 @@ class GooglePlayAPI(object):
|
|||||||
# list apps for specific subcat
|
# list apps for specific subcat
|
||||||
for cluster in data.payload.listResponse.cluster:
|
for cluster in data.payload.listResponse.cluster:
|
||||||
for doc in cluster.doc:
|
for doc in cluster.doc:
|
||||||
output += list(map(utils.fromDocToDictionary,
|
apps = [a for a in doc.child]
|
||||||
[a for a in doc.child]))
|
apps = list(map(utils.fromDocToDictionary,
|
||||||
|
apps))
|
||||||
|
output += apps
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def reviews(self, packageName, filterByDevice=False, sort=2,
|
def reviews(self, packageName, filterByDevice=False, sort=2,
|
||||||
@ -416,7 +410,6 @@ class GooglePlayAPI(object):
|
|||||||
'commentId': r.commentId,
|
'commentId': r.commentId,
|
||||||
'author': r.author2.name} for r in reviews]
|
'author': r.author2.name} for r in reviews]
|
||||||
|
|
||||||
|
|
||||||
def delivery(self, packageName, versionCode,
|
def delivery(self, packageName, versionCode,
|
||||||
offerType=1, downloadToken=None, progress_bar=False):
|
offerType=1, downloadToken=None, progress_bar=False):
|
||||||
"""Download an already purchased app.
|
"""Download an already purchased app.
|
||||||
@ -472,7 +465,7 @@ class GooglePlayAPI(object):
|
|||||||
versionCode can be grabbed by using the details() method on the given
|
versionCode can be grabbed by using the details() method on the given
|
||||||
app."""
|
app."""
|
||||||
|
|
||||||
if self.authSubToken == None:
|
if self.authSubToken is None:
|
||||||
raise Exception("You need to login before executing any request")
|
raise Exception("You need to login before executing any request")
|
||||||
|
|
||||||
path = "purchase"
|
path = "purchase"
|
||||||
|
@ -3,6 +3,7 @@ import sys
|
|||||||
|
|
||||||
VERSION = sys.version_info[0]
|
VERSION = sys.version_info[0]
|
||||||
|
|
||||||
|
|
||||||
def fromDocToDictionary(app):
|
def fromDocToDictionary(app):
|
||||||
return {
|
return {
|
||||||
"docId": app.docid,
|
"docId": app.docid,
|
||||||
@ -57,6 +58,7 @@ def fromDocToDictionary(app):
|
|||||||
"detailsUrl": app.detailsUrl
|
"detailsUrl": app.detailsUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def readInt(byteArray, start):
|
def readInt(byteArray, start):
|
||||||
"""Read the byte array, starting from *start* position,
|
"""Read the byte array, starting from *start* position,
|
||||||
as an 32-bit unsigned integer"""
|
as an 32-bit unsigned integer"""
|
||||||
|
Loading…
Reference in New Issue
Block a user