mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 12:54:58 +00:00
Removed caching code + better search() behaviour
The old caching code could cause a query to be cached for ever, returning always the same set of result for a specific query. This is not a good behaviour, since search results change continuously. In the future, this behaviour could be reintroduced with a better logic (for example, check if the query was in cache longer than some hours or days) Signed-off-by: Domenico Iezzi <domenico.iezzi.201@gmail.com>
This commit is contained in:
parent
f4799d3567
commit
dda3a2f39f
@ -56,7 +56,6 @@ class GooglePlayAPI(object):
|
|||||||
|
|
||||||
def __init__(self, debug=False):
|
def __init__(self, debug=False):
|
||||||
# you must use a device-associated androidId value
|
# you must use a device-associated androidId value
|
||||||
self.preFetch = {}
|
|
||||||
self.lang = config.LANG
|
self.lang = config.LANG
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
@ -81,12 +80,6 @@ class GooglePlayAPI(object):
|
|||||||
h = b'\x00' + SHA.new(binaryKey).digest()[0:4]
|
h = b'\x00' + SHA.new(binaryKey).digest()[0:4]
|
||||||
return base64.urlsafe_b64encode(h + encrypted)
|
return base64.urlsafe_b64encode(h + encrypted)
|
||||||
|
|
||||||
def _try_register_preFetch(self, protoObj):
|
|
||||||
fields = [i.name for (i, _) in protoObj.ListFields()]
|
|
||||||
if ("preFetch" in fields):
|
|
||||||
for p in protoObj.preFetch:
|
|
||||||
self.preFetch[p.url] = p.response
|
|
||||||
|
|
||||||
def setAuthSubToken(self, authSubToken):
|
def setAuthSubToken(self, authSubToken):
|
||||||
self.authSubToken = authSubToken
|
self.authSubToken = authSubToken
|
||||||
|
|
||||||
@ -248,9 +241,6 @@ class GooglePlayAPI(object):
|
|||||||
post_content_type="application/x-www-form-urlencoded; charset=UTF-8"):
|
post_content_type="application/x-www-form-urlencoded; charset=UTF-8"):
|
||||||
if self.authSubToken == None:
|
if self.authSubToken == None:
|
||||||
raise Exception("You need to login before executing any request")
|
raise Exception("You need to login before executing any request")
|
||||||
if (datapost is None and path in self.preFetch):
|
|
||||||
data = self.preFetch[path]
|
|
||||||
else:
|
|
||||||
headers = self.getDefaultHeaders()
|
headers = self.getDefaultHeaders()
|
||||||
|
|
||||||
if datapost is not None:
|
if datapost is not None:
|
||||||
@ -267,11 +257,16 @@ class GooglePlayAPI(object):
|
|||||||
message = googleplay_pb2.ResponseWrapper.FromString(response.content)
|
message = googleplay_pb2.ResponseWrapper.FromString(response.content)
|
||||||
if message.commands.displayErrorMessage != "":
|
if message.commands.displayErrorMessage != "":
|
||||||
raise RequestError(message.commands.displayErrorMessage)
|
raise RequestError(message.commands.displayErrorMessage)
|
||||||
self._try_register_preFetch(message)
|
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def search(self, query, nb_result, offset=None):
|
def search(self, query, nb_result, offset=None):
|
||||||
|
""" Search the play store for an app.
|
||||||
|
|
||||||
|
nb_result is the maximum number of result to be returned.
|
||||||
|
|
||||||
|
offset is used to take result starting from an index.
|
||||||
|
"""
|
||||||
if self.authSubToken == None:
|
if self.authSubToken == None:
|
||||||
raise Exception("You need to login before executing any request")
|
raise Exception("You need to login before executing any request")
|
||||||
|
|
||||||
@ -284,10 +279,17 @@ class GooglePlayAPI(object):
|
|||||||
while remaining > 0 and nextPath != None:
|
while remaining > 0 and nextPath != None:
|
||||||
currentPath = nextPath
|
currentPath = nextPath
|
||||||
data = self.executeRequestApi2(currentPath)
|
data = self.executeRequestApi2(currentPath)
|
||||||
if len(data.preFetch) == 0:
|
if len(data.preFetch) > 0:
|
||||||
cluster = data.payload.listResponse.cluster[0]
|
response = data.preFetch[0].response
|
||||||
else:
|
else:
|
||||||
cluster = data.preFetch[0].response.payload.listResponse.cluster[0]
|
response = data
|
||||||
|
if response.payload.HasField('searchResponse'):
|
||||||
|
# we still need to fetch the first page, so go to
|
||||||
|
# next loop iteration without decrementing counter
|
||||||
|
nextPath = response.payload.searchResponse.nextPageUrl
|
||||||
|
continue
|
||||||
|
|
||||||
|
cluster = response.payload.listResponse.cluster[0]
|
||||||
if cluster.doc[0].containerMetadata.nextPageUrl != "":
|
if cluster.doc[0].containerMetadata.nextPageUrl != "":
|
||||||
nextPath = cluster.doc[0].containerMetadata.nextPageUrl
|
nextPath = cluster.doc[0].containerMetadata.nextPageUrl
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user