mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-25 14:24:56 +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)
|
return utils.parseProtobufObj(data.payload.browseResponse)
|
||||||
|
|
||||||
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 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.
|
Args:
|
||||||
|
cat (str): category id
|
||||||
If ctr is provided, list apps within this subcategory."""
|
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))
|
path = LIST_URL + "?c=3&cat={}".format(requests.utils.quote(cat))
|
||||||
if ctr is not None:
|
if ctr is not None:
|
||||||
path += "&ctr={}".format(requests.utils.quote(ctr))
|
path += "&ctr={}".format(requests.utils.quote(ctr))
|
||||||
if nb_results is not None:
|
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:
|
if offset is not None:
|
||||||
path += "&o={}".format(requests.utils.quote(offset))
|
path += "&o={}".format(requests.utils.quote(str(offset)))
|
||||||
data = self.executeRequestApi2(path)
|
data = self.executeRequestApi2(path)
|
||||||
clusters = []
|
clusters = []
|
||||||
docs = []
|
docs = []
|
||||||
@ -451,8 +460,8 @@ class GooglePlayAPI(object):
|
|||||||
return [c.docid for c in clusters]
|
return [c.docid for c in clusters]
|
||||||
else:
|
else:
|
||||||
apps = []
|
apps = []
|
||||||
for d in data.payload.listResponse.doc:
|
for d in data.payload.listResponse.doc: # categories
|
||||||
for c in d.child: # category
|
for c in d.child: # sub-category
|
||||||
for a in c.child: # app
|
for a in c.child: # app
|
||||||
apps.append(utils.parseProtobufObj(a))
|
apps.append(utils.parseProtobufObj(a))
|
||||||
return apps
|
return apps
|
||||||
|
@ -88,12 +88,14 @@ for doc in browseCat:
|
|||||||
|
|
||||||
# LIST
|
# LIST
|
||||||
cat = "MUSIC_AND_AUDIO"
|
cat = "MUSIC_AND_AUDIO"
|
||||||
print("\nList %s subcategories\n" % cat)
|
print("\nList {} subcategories\n".format(cat))
|
||||||
catList = server.list(cat)
|
catList = server.list(cat)
|
||||||
for c in catList:
|
for c in catList:
|
||||||
print(c)
|
print(c)
|
||||||
|
|
||||||
print("\nList %s apps for %s category\n" % (catList[0], cat))
|
limit = 4
|
||||||
appList = server.list(cat, catList[0])
|
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:
|
for app in appList:
|
||||||
print(app["docid"])
|
print(app["docid"])
|
||||||
|
Loading…
Reference in New Issue
Block a user