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,11 +379,17 @@ 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:
|
|
||||||
|
output = []
|
||||||
|
clusters = []
|
||||||
|
|
||||||
|
if utils.hasPrefetch(data):
|
||||||
|
clusters = chain.from_iterable([pf.response.payload.listResponse.cluster
|
||||||
|
for pf in data.preFetch])
|
||||||
|
|
||||||
# result contains apps of a specific category
|
# result contains apps of a specific category
|
||||||
# organized by sections
|
# organized by sections
|
||||||
for pf in data.preFetch:
|
for cluster in clusters:
|
||||||
for cluster in pf.response.payload.listResponse.cluster:
|
|
||||||
for doc in cluster.doc:
|
for doc in cluster.doc:
|
||||||
apps = [a for a in doc.child]
|
apps = [a for a in doc.child]
|
||||||
apps = list(map(utils.fromDocToDictionary,
|
apps = list(map(utils.fromDocToDictionary,
|
||||||
|
@ -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