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:
|
||||
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)
|
||||
device = {}
|
||||
|
||||
|
||||
def getDevicesCodenames():
|
||||
return config.sections()
|
||||
|
||||
|
||||
def getDeviceConfig():
|
||||
libList = device['sharedlibraries'].split(",")
|
||||
featureList = device['features'].split(",")
|
||||
@ -61,6 +64,7 @@ def getDeviceConfig():
|
||||
deviceConfig.glExtension.append(x)
|
||||
return deviceConfig
|
||||
|
||||
|
||||
def getAndroidBuild():
|
||||
androidBuild = googleplay_pb2.AndroidBuildProto()
|
||||
androidBuild.id = device['build.fingerprint']
|
||||
@ -79,6 +83,7 @@ def getAndroidBuild():
|
||||
androidBuild.googleServices = int(device['gsf.version'])
|
||||
return androidBuild
|
||||
|
||||
|
||||
def getAndroidCheckin():
|
||||
androidCheckin = googleplay_pb2.AndroidCheckinProto()
|
||||
androidCheckin.build.CopyFrom(getAndroidBuild())
|
||||
@ -89,6 +94,7 @@ def getAndroidCheckin():
|
||||
androidCheckin.userNumber = 0
|
||||
return androidCheckin
|
||||
|
||||
|
||||
def getAndroidCheckinRequest(device_codename):
|
||||
for (key, value) in config.items(device_codename):
|
||||
device[key] = value
|
||||
|
@ -1,10 +1,6 @@
|
||||
#!/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.PublicKey import RSA
|
||||
from Crypto.Hash import SHA
|
||||
@ -13,7 +9,6 @@ from clint.textui import progress
|
||||
|
||||
import requests
|
||||
import base64
|
||||
import struct
|
||||
import itertools
|
||||
|
||||
from . import googleplay_pb2, config, utils
|
||||
@ -116,8 +111,6 @@ class GooglePlayAPI(object):
|
||||
response = googleplay_pb2.AndroidCheckinResponse()
|
||||
response.ParseFromString(res.content)
|
||||
|
||||
securityToken = "{0:x}".format(response.securityToken)
|
||||
|
||||
# checkin again to upload gfsid
|
||||
request2 = googleplay_pb2.AndroidCheckinRequest()
|
||||
request2.CopyFrom(request)
|
||||
@ -126,7 +119,7 @@ class GooglePlayAPI(object):
|
||||
request2.accountCookie.append("[" + email + "]")
|
||||
request2.accountCookie.append(ac2dmToken)
|
||||
stringRequest = request2.SerializeToString()
|
||||
res2 = requests.post(self.CHECKINURL, data=stringRequest,
|
||||
requests.post(self.CHECKINURL, data=stringRequest,
|
||||
headers=headers, verify=ssl_verify)
|
||||
|
||||
return response.androidId
|
||||
@ -146,8 +139,7 @@ class GooglePlayAPI(object):
|
||||
stringRequest = upload.SerializeToString()
|
||||
res = requests.post(self.UPLOADURL, data=stringRequest,
|
||||
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'):
|
||||
"""Login to your Google Account.
|
||||
@ -239,7 +231,7 @@ class GooglePlayAPI(object):
|
||||
|
||||
def executeRequestApi2(self, path, datapost=None,
|
||||
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")
|
||||
headers = self.getDefaultHeaders()
|
||||
|
||||
@ -267,7 +259,7 @@ class GooglePlayAPI(object):
|
||||
|
||||
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")
|
||||
|
||||
remaining = nb_result
|
||||
@ -276,7 +268,7 @@ class GooglePlayAPI(object):
|
||||
nextPath = "search?c=3&q=%s" % requests.utils.quote(query)
|
||||
if (offset is not None):
|
||||
nextPath += "&o=%d" % int(offset)
|
||||
while remaining > 0 and nextPath != None:
|
||||
while remaining > 0 and nextPath is not None:
|
||||
currentPath = nextPath
|
||||
data = self.executeRequestApi2(currentPath)
|
||||
if len(data.preFetch) > 0:
|
||||
@ -357,12 +349,13 @@ class GooglePlayAPI(object):
|
||||
for pf in data.preFetch:
|
||||
for cluster in pf.response.payload.listResponse.cluster:
|
||||
for doc in cluster.doc:
|
||||
apps = [a for a in doc.child]
|
||||
apps = list(map(utils.fromDocToDictionary,
|
||||
apps))
|
||||
section = {'title': doc.title,
|
||||
'docid': doc.docid,
|
||||
'apps': list(map(utils.fromDocToDictionary,
|
||||
[a for a in doc.child])) }
|
||||
'apps': apps}
|
||||
output.append(section)
|
||||
|
||||
return output
|
||||
|
||||
def list(self, cat, ctr=None, nb_results=None, offset=None):
|
||||
@ -390,9 +383,10 @@ class GooglePlayAPI(object):
|
||||
# list apps for specific subcat
|
||||
for cluster in data.payload.listResponse.cluster:
|
||||
for doc in cluster.doc:
|
||||
output += list(map(utils.fromDocToDictionary,
|
||||
[a for a in doc.child]))
|
||||
|
||||
apps = [a for a in doc.child]
|
||||
apps = list(map(utils.fromDocToDictionary,
|
||||
apps))
|
||||
output += apps
|
||||
return output
|
||||
|
||||
def reviews(self, packageName, filterByDevice=False, sort=2,
|
||||
@ -416,7 +410,6 @@ class GooglePlayAPI(object):
|
||||
'commentId': r.commentId,
|
||||
'author': r.author2.name} for r in reviews]
|
||||
|
||||
|
||||
def delivery(self, packageName, versionCode,
|
||||
offerType=1, downloadToken=None, progress_bar=False):
|
||||
"""Download an already purchased app.
|
||||
@ -472,7 +465,7 @@ class GooglePlayAPI(object):
|
||||
versionCode can be grabbed by using the details() method on the given
|
||||
app."""
|
||||
|
||||
if self.authSubToken == None:
|
||||
if self.authSubToken is None:
|
||||
raise Exception("You need to login before executing any request")
|
||||
|
||||
path = "purchase"
|
||||
|
@ -3,6 +3,7 @@ import sys
|
||||
|
||||
VERSION = sys.version_info[0]
|
||||
|
||||
|
||||
def fromDocToDictionary(app):
|
||||
return {
|
||||
"docId": app.docid,
|
||||
@ -57,6 +58,7 @@ def fromDocToDictionary(app):
|
||||
"detailsUrl": app.detailsUrl
|
||||
}
|
||||
|
||||
|
||||
def readInt(byteArray, start):
|
||||
"""Read the byte array, starting from *start* position,
|
||||
as an 32-bit unsigned integer"""
|
||||
|
Loading…
Reference in New Issue
Block a user