Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
Domenico Iezzi 2017-10-05 20:39:24 +02:00
parent 0a5e270049
commit 73081ee57a
2 changed files with 49 additions and 37 deletions

View File

@ -274,19 +274,31 @@ class GooglePlayAPI(object):
def search(self, query, nb_result, offset=None):
if self.authSubToken == None:
raise Exception("You need to login before executing any request")
path = "search?c=3&q=%s" % requests.utils.quote(query)
remaining = nb_result
output = []
nextPath = "search?c=3&q=%s" % requests.utils.quote(query)
if (offset is not None):
path += "&o=%d" % int(offset)
data = self.executeRequestApi2(path)
# TODO: can response contain more than 1 cluster?
nextPath += "&o=%d" % int(offset)
while remaining > 0 and nextPath != None:
currentPath = nextPath
data = self.executeRequestApi2(currentPath)
if len(data.preFetch) == 0:
cluster = data.payload.listResponse.cluster[0]
else:
cluster = data.preFetch[0].response.payload.listResponse.cluster[0]
# cluster has more than 1 doc usually, and each doc has some
# childs representing the applications. So we chain together every child
# of every doc
apps = itertools.chain.from_iterable([doc.child for doc in cluster.doc])
output = list(map(utils.fromDocToDictionary, apps))
if cluster.doc[0].containerMetadata.nextPageUrl != "":
nextPath = cluster.doc[0].containerMetadata.nextPageUrl
else:
nextPath = None
apps = list(itertools.chain.from_iterable([doc.child for doc in cluster.doc]))
output += list(map(utils.fromDocToDictionary, apps))
remaining -= len(apps)
if len(output) > nb_result:
output = output[:nb_result]
return output
def details(self, packageName):

10
test.py
View File

@ -8,7 +8,6 @@ PASSWD = "fjgozwjmkwyvvutt"
testApps = ['com.cpuid.cpu_z']
server = GooglePlayAPI(debug=True)
try:
print('\nLogging in with email and password\n')
server.login(EMAIL, PASSWD, None, None)
gsfId = server.gsfId
@ -18,7 +17,11 @@ try:
server = GooglePlayAPI(debug=True)
server.login(None, None, gsfId, authSubToken)
apps = server.search('telegram', 1, None)
apps = server.search('telegram', 34, None)
print('nb_result: 34')
print('number of results: %d' % len(apps))
print('\nFound those apps:\n')
for a in apps:
print(a['docId'])
@ -34,6 +37,3 @@ try:
print('\nGetting details for %s\n' % testApps[0])
bulk = server.bulkDetails(testApps)
print(bulk)
except Exception as e:
print(str(e))
sys.exit(1)