mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-25 06:14:58 +00:00
Improve list() documentation and test case
This commit is contained in:
parent
af10ec6494
commit
c119d1ce5b
@ -428,18 +428,27 @@ class GooglePlayAPI(object):
|
||||
return utils.parseProtobufObj(data.payload.browseResponse)
|
||||
|
||||
def list(self, cat, ctr=None, nb_results=None, offset=None):
|
||||
"""List apps for a specfic category *cat*.
|
||||
"""List all possible subcategories for a specific category. If
|
||||
also a subcategory is provided, list apps from this category.
|
||||
|
||||
If ctr (subcategory ID) is None, returns a list of valid subcategories.
|
||||
|
||||
If ctr is provided, list apps within this subcategory."""
|
||||
Args:
|
||||
cat (str): category id
|
||||
ctr (str): subcategory id
|
||||
nb_results (int): if a subcategory is specified, limit number
|
||||
of results to this number
|
||||
offset (int): if a subcategory is specified, start counting from this
|
||||
result
|
||||
Returns:
|
||||
A list of categories. If subcategory is specified, a list of apps in this
|
||||
category.
|
||||
"""
|
||||
path = LIST_URL + "?c=3&cat={}".format(requests.utils.quote(cat))
|
||||
if ctr is not None:
|
||||
path += "&ctr={}".format(requests.utils.quote(ctr))
|
||||
if nb_results is not None:
|
||||
path += "&n={}".format(requests.utils.quote(nb_results))
|
||||
path += "&n={}".format(requests.utils.quote(str(nb_results)))
|
||||
if offset is not None:
|
||||
path += "&o={}".format(requests.utils.quote(offset))
|
||||
path += "&o={}".format(requests.utils.quote(str(offset)))
|
||||
data = self.executeRequestApi2(path)
|
||||
clusters = []
|
||||
docs = []
|
||||
@ -451,8 +460,8 @@ class GooglePlayAPI(object):
|
||||
return [c.docid for c in clusters]
|
||||
else:
|
||||
apps = []
|
||||
for d in data.payload.listResponse.doc:
|
||||
for c in d.child: # category
|
||||
for d in data.payload.listResponse.doc: # categories
|
||||
for c in d.child: # sub-category
|
||||
for a in c.child: # app
|
||||
apps.append(utils.parseProtobufObj(a))
|
||||
return apps
|
||||
|
@ -88,12 +88,14 @@ for doc in browseCat:
|
||||
|
||||
# LIST
|
||||
cat = "MUSIC_AND_AUDIO"
|
||||
print("\nList %s subcategories\n" % cat)
|
||||
print("\nList {} subcategories\n".format(cat))
|
||||
catList = server.list(cat)
|
||||
for c in catList:
|
||||
print(c)
|
||||
|
||||
print("\nList %s apps for %s category\n" % (catList[0], cat))
|
||||
appList = server.list(cat, catList[0])
|
||||
limit = 4
|
||||
print("\nList only {} apps from subcat {} for {} category\n".format(
|
||||
limit, catList[0], cat))
|
||||
appList = server.list(cat, catList[0], 4, 1)
|
||||
for app in appList:
|
||||
print(app["docid"])
|
||||
|
Loading…
Reference in New Issue
Block a user