mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 12:54:58 +00:00
Improvements to helper functions
This commit is contained in:
parent
55499a015e
commit
8dc2eb58c7
@ -347,7 +347,7 @@ class GooglePlayAPI(object):
|
|||||||
packageNames (list): a list of app IDs (usually starting with 'com.').
|
packageNames (list): a list of app IDs (usually starting with 'com.').
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
a list of dictionaries containing docv1 data, or None
|
a list of dictionaries containing docv2 data, or None
|
||||||
if the app doesn't exist"""
|
if the app doesn't exist"""
|
||||||
|
|
||||||
path = "bulkDetails"
|
path = "bulkDetails"
|
||||||
@ -358,7 +358,7 @@ class GooglePlayAPI(object):
|
|||||||
data.decode("utf-8"),
|
data.decode("utf-8"),
|
||||||
"application/x-protobuf")
|
"application/x-protobuf")
|
||||||
response = message.payload.bulkDetailsResponse
|
response = message.payload.bulkDetailsResponse
|
||||||
return [None if not entry.HasField('doc') else
|
return [None if not utils.hasDoc(entry) else
|
||||||
utils.fromDocToDictionary(entry.doc)
|
utils.fromDocToDictionary(entry.doc)
|
||||||
for entry in response.entry]
|
for entry in response.entry]
|
||||||
|
|
||||||
@ -372,7 +372,6 @@ class GooglePlayAPI(object):
|
|||||||
if subCat is not None:
|
if subCat is not None:
|
||||||
path += "&ctr=%s" % requests.utils.quote(subCat)
|
path += "&ctr=%s" % requests.utils.quote(subCat)
|
||||||
data = self.executeRequestApi2(path)
|
data = self.executeRequestApi2(path)
|
||||||
output = []
|
|
||||||
|
|
||||||
if cat is None and subCat is None:
|
if cat is None and subCat is None:
|
||||||
# result contains all categories available
|
# result contains all categories available
|
||||||
@ -380,19 +379,25 @@ class GooglePlayAPI(object):
|
|||||||
'dataUrl': c.dataUrl,
|
'dataUrl': c.dataUrl,
|
||||||
'catId': c.unknownCategoryContainer.categoryIdContainer.categoryId}
|
'catId': c.unknownCategoryContainer.categoryIdContainer.categoryId}
|
||||||
for c in data.payload.browseResponse.category]
|
for c in data.payload.browseResponse.category]
|
||||||
else:
|
|
||||||
# result contains apps of a specific category
|
output = []
|
||||||
# organized by sections
|
clusters = []
|
||||||
for pf in data.preFetch:
|
|
||||||
for cluster in pf.response.payload.listResponse.cluster:
|
if utils.hasPrefetch(data):
|
||||||
for doc in cluster.doc:
|
clusters = chain.from_iterable([pf.response.payload.listResponse.cluster
|
||||||
apps = [a for a in doc.child]
|
for pf in data.preFetch])
|
||||||
apps = list(map(utils.fromDocToDictionary,
|
|
||||||
apps))
|
# result contains apps of a specific category
|
||||||
section = {'title': doc.title,
|
# organized by sections
|
||||||
'docid': doc.docid,
|
for cluster in clusters:
|
||||||
'apps': apps}
|
for doc in cluster.doc:
|
||||||
output.append(section)
|
apps = [a for a in doc.child]
|
||||||
|
apps = list(map(utils.fromDocToDictionary,
|
||||||
|
apps))
|
||||||
|
section = {'title': doc.title,
|
||||||
|
'docid': doc.docid,
|
||||||
|
'apps': apps}
|
||||||
|
output.append(section)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def list(self, cat, ctr=None, nb_results=None, offset=None):
|
def list(self, cat, ctr=None, nb_results=None, offset=None):
|
||||||
|
@ -69,26 +69,33 @@ def toBigInt(byteArray):
|
|||||||
out = out | decoded << key * 8
|
out = out | decoded << key * 8
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def hasPrefetch(response):
|
def hasPrefetch(obj):
|
||||||
if type(response) is not googleplay_pb2.ResponseWrapper:
|
|
||||||
return False
|
|
||||||
try:
|
try:
|
||||||
return response.HasField('preFetch')
|
return len(obj.preFetch) > 0
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def hasListResponse(payload):
|
def hasListResponse(obj):
|
||||||
if type(payload) is not googleplay_pb2.Payload:
|
|
||||||
return False
|
|
||||||
try:
|
try:
|
||||||
return payload.HasField('listResponse')
|
return obj.HasField('listResponse')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def hasSearchResponse(payload):
|
def hasSearchResponse(obj):
|
||||||
if type(payload) is not googleplay_pb2.Payload:
|
|
||||||
return False
|
|
||||||
try:
|
try:
|
||||||
return payload.HasField('searchResponse')
|
return obj.HasField('searchResponse')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def hasDoc(obj):
|
||||||
|
# doc an be a single object or a
|
||||||
|
# RepeatedComposite object
|
||||||
|
try:
|
||||||
|
existance = obj.HasField('doc')
|
||||||
|
except ValueError:
|
||||||
|
try:
|
||||||
|
existance = len(obj.doc) > 0
|
||||||
|
except TypeError:
|
||||||
|
existance = False
|
||||||
|
|
||||||
|
return existance
|
||||||
|
Loading…
Reference in New Issue
Block a user