Return complete messages for some APIs

This commit is contained in:
Domenico Iezzi 2018-12-23 22:36:55 +01:00
parent 6c8d295369
commit 129d45f19b
No known key found for this signature in database
GPG Key ID: D8CE73FC9E4393C3

View File

@ -343,19 +343,16 @@ class GooglePlayAPI(object):
"ssis": "120", "ssis": "120",
"sst": "2"} "sst": "2"}
data = self.executeRequestApi2(SEARCH_SUGGEST_URL, params=params) data = self.executeRequestApi2(SEARCH_SUGGEST_URL, params=params)
output = [] entryIterator = data.payload.searchSuggestResponse.entry
for entry in data.payload.searchSuggestResponse.entry: return list(map(utils.parseProtobufObj, entryIterator))
output.append(utils.parseProtobufObj(entry))
return output
def search(self, query, nb_result, offset=None): def search(self, query, nb_result, offset=None):
""" Search the play store for an app. """ Search the play store for an app.
nb_result is the maximum number of result to be returned. nb_result (int): is the maximum number of result to be returned
offset is used to take result starting from an index. offset (int): is used to take result starting from an index.
""" """
# TODO: correctly implement nb_results (for now it does nothing)
if self.authSubToken is 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")
@ -365,17 +362,15 @@ class GooglePlayAPI(object):
path = SEARCH_URL + "?c=3&q={}".format(requests.utils.quote(query)) path = SEARCH_URL + "?c=3&q={}".format(requests.utils.quote(query))
if (offset is not None): if (offset is not None):
nextPath += "&o={}".format(offset) nextPath += "&o={}".format(offset)
# TODO: not sure if this toc call should be here # FIXME: not sure if this toc call should be here
self.toc() self.toc()
data = self.executeRequestApi2(path) data = self.executeRequestApi2(path)
if utils.hasPrefetch(data): if utils.hasPrefetch(data):
response = data.preFetch[0].response response = data.preFetch[0].response
else: else:
response = data response = data
output = [] resIterator = response.payload.listResponse.doc
for cluster in response.payload.listResponse.doc[0].child: return list(map(utils.parseProtobufObj, resIterator))
output.append(utils.parseProtobufObj(cluster))
return output
def details(self, packageName): def details(self, packageName):
"""Get app details from a package name. """Get app details from a package name.
@ -412,17 +407,17 @@ class GooglePlayAPI(object):
utils.parseProtobufObj(entry.doc) utils.parseProtobufObj(entry.doc)
for entry in response.entry] for entry in response.entry]
def getHomeApps(self): def home(self, cat=None):
path = HOME_URL + "?c=3&nocache_isui=true" path = HOME_URL + "?c=3&nocache_isui=true"
if cat is not None:
path += "&cat={}".format(cat)
data = self.executeRequestApi2(path) data = self.executeRequestApi2(path)
if utils.hasPrefetch(data): if utils.hasPrefetch(data):
response = data.preFetch[0].response response = data.preFetch[0].response
else: else:
response = data response = data
output = [] resIterator = response.payload.listResponse.doc
for cluster in response.payload.listResponse.doc[0].child: return list(map(utils.parseProtobufObj, resIterator))
output.append(utils.parseProtobufObj(cluster))
return output
def browse(self, cat=None, subCat=None): def browse(self, cat=None, subCat=None):
"""Browse categories. If neither cat nor subcat are specified, """Browse categories. If neither cat nor subcat are specified,
@ -435,29 +430,7 @@ class GooglePlayAPI(object):
path += "&ctr={}".format(requests.utils.quote(subCat)) path += "&ctr={}".format(requests.utils.quote(subCat))
data = self.executeRequestApi2(path) data = self.executeRequestApi2(path)
if cat is None and subCat is None: return utils.parseProtobufObj(data.payload.browseResponse)
# result contains all categories available
return [utils.parseProtobufObj(c) for c in data.payload.browseResponse.category]
output = []
clusters = []
if utils.hasPrefetch(data):
for pf in data.preFetch:
for cluster in pf.response.payload.listResponse.doc:
clusters.extend(cluster.child)
# result contains apps of a specific category
# organized by sections
for cluster in clusters:
apps = [a for a in cluster.child]
apps = list(map(utils.parseProtobufObj,
apps))
section = {'title': cluster.title,
'docid': cluster.docid,
'apps': apps}
output.append(section)
return output
def list(self, cat, ctr=None, nb_results=None, offset=None): def list(self, cat, ctr=None, nb_results=None, offset=None):
"""List apps for a specfic category *cat*. """List apps for a specfic category *cat*.