mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 21:04:59 +00:00
Helper functions for response parsing
This commit is contained in:
parent
6a6c0b01d0
commit
55499a015e
@ -63,7 +63,6 @@ class GooglePlayAPI(object):
|
|||||||
self.deviceBuilder.device['simoperator'] = sim_operator
|
self.deviceBuilder.device['simoperator'] = sim_operator
|
||||||
if cell_operator is not None:
|
if cell_operator is not None:
|
||||||
self.deviceBuilder.device['celloperator'] = cell_operator
|
self.deviceBuilder.device['celloperator'] = cell_operator
|
||||||
# save last response text for error logging
|
|
||||||
|
|
||||||
def encrypt_password(self, login, passwd):
|
def encrypt_password(self, login, passwd):
|
||||||
"""Encrypt the password using the google publickey, using
|
"""Encrypt the password using the google publickey, using
|
||||||
@ -298,24 +297,23 @@ class GooglePlayAPI(object):
|
|||||||
while remaining > 0 and nextPath is not None:
|
while remaining > 0 and nextPath is not None:
|
||||||
currentPath = nextPath
|
currentPath = nextPath
|
||||||
data = self.executeRequestApi2(currentPath)
|
data = self.executeRequestApi2(currentPath)
|
||||||
if len(data.preFetch) > 0:
|
if utils.hasPrefetch(data):
|
||||||
response = data.preFetch[0].response
|
response = data.preFetch[0].response
|
||||||
else:
|
else:
|
||||||
response = data
|
response = data
|
||||||
if response.payload.HasField('searchResponse'):
|
if utils.hasSearchResponse(response.payload):
|
||||||
# we still need to fetch the first page, so go to
|
# we still need to fetch the first page, so go to
|
||||||
# next loop iteration without decrementing counter
|
# next loop iteration without decrementing counter
|
||||||
nextPath = response.payload.searchResponse.nextPageUrl
|
nextPath = response.payload.searchResponse.nextPageUrl
|
||||||
continue
|
continue
|
||||||
|
if utils.hasListResponse(response.payload):
|
||||||
if len(response.payload.listResponse.cluster) == 0:
|
cluster = response.payload.listResponse.cluster
|
||||||
# strange behaviour, probably due to
|
if len(cluster) == 0:
|
||||||
# expired token
|
# strange behaviour, probably due to expired token
|
||||||
raise LoginError('Unexpected behaviour, probably expired '
|
raise LoginError('Unexpected behaviour, probably expired '
|
||||||
'token')
|
'token')
|
||||||
cluster = response.payload.listResponse.cluster[0]
|
cluster = cluster[0]
|
||||||
if len(cluster.doc) == 0:
|
if len(cluster.doc) == 0:
|
||||||
print('No results for query %s' % query)
|
|
||||||
break
|
break
|
||||||
if cluster.doc[0].containerMetadata.nextPageUrl != "":
|
if cluster.doc[0].containerMetadata.nextPageUrl != "":
|
||||||
nextPath = cluster.doc[0].containerMetadata.nextPageUrl
|
nextPath = cluster.doc[0].containerMetadata.nextPageUrl
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
from . import googleplay_pb2
|
||||||
|
|
||||||
VERSION = sys.version_info[0]
|
VERSION = sys.version_info[0]
|
||||||
|
|
||||||
|
|
||||||
def fromDocToDictionary(app):
|
def fromDocToDictionary(app):
|
||||||
return {"docId": app.docid,
|
return {"docId": app.docid,
|
||||||
"title": app.title,
|
"title": app.title,
|
||||||
@ -68,3 +68,27 @@ def toBigInt(byteArray):
|
|||||||
decoded = struct.unpack("B", value)[0]
|
decoded = struct.unpack("B", value)[0]
|
||||||
out = out | decoded << key * 8
|
out = out | decoded << key * 8
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
def hasPrefetch(response):
|
||||||
|
if type(response) is not googleplay_pb2.ResponseWrapper:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
return response.HasField('preFetch')
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def hasListResponse(payload):
|
||||||
|
if type(payload) is not googleplay_pb2.Payload:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
return payload.HasField('listResponse')
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def hasSearchResponse(payload):
|
||||||
|
if type(payload) is not googleplay_pb2.Payload:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
return payload.HasField('searchResponse')
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user