mirror of
https://github.com/FliegendeWurst/googleplay-api.git
synced 2024-11-22 12:54:58 +00:00
parent
0a5e270049
commit
73081ee57a
@ -274,19 +274,31 @@ class GooglePlayAPI(object):
|
|||||||
def search(self, query, nb_result, offset=None):
|
def search(self, query, nb_result, offset=None):
|
||||||
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")
|
||||||
path = "search?c=3&q=%s" % requests.utils.quote(query)
|
|
||||||
|
|
||||||
|
remaining = nb_result
|
||||||
|
output = []
|
||||||
|
|
||||||
|
nextPath = "search?c=3&q=%s" % requests.utils.quote(query)
|
||||||
if (offset is not None):
|
if (offset is not None):
|
||||||
path += "&o=%d" % int(offset)
|
nextPath += "&o=%d" % int(offset)
|
||||||
|
while remaining > 0 and nextPath != None:
|
||||||
data = self.executeRequestApi2(path)
|
currentPath = nextPath
|
||||||
# TODO: can response contain more than 1 cluster?
|
data = self.executeRequestApi2(currentPath)
|
||||||
|
if len(data.preFetch) == 0:
|
||||||
|
cluster = data.payload.listResponse.cluster[0]
|
||||||
|
else:
|
||||||
cluster = data.preFetch[0].response.payload.listResponse.cluster[0]
|
cluster = data.preFetch[0].response.payload.listResponse.cluster[0]
|
||||||
# cluster has more than 1 doc usually, and each doc has some
|
if cluster.doc[0].containerMetadata.nextPageUrl != "":
|
||||||
# childs representing the applications. So we chain together every child
|
nextPath = cluster.doc[0].containerMetadata.nextPageUrl
|
||||||
# of every doc
|
else:
|
||||||
apps = itertools.chain.from_iterable([doc.child for doc in cluster.doc])
|
nextPath = None
|
||||||
output = list(map(utils.fromDocToDictionary, apps))
|
apps = list(itertools.chain.from_iterable([doc.child for doc in cluster.doc]))
|
||||||
|
output += list(map(utils.fromDocToDictionary, apps))
|
||||||
|
remaining -= len(apps)
|
||||||
|
|
||||||
|
if len(output) > nb_result:
|
||||||
|
output = output[:nb_result]
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def details(self, packageName):
|
def details(self, packageName):
|
||||||
|
10
test.py
10
test.py
@ -8,7 +8,6 @@ PASSWD = "fjgozwjmkwyvvutt"
|
|||||||
testApps = ['com.cpuid.cpu_z']
|
testApps = ['com.cpuid.cpu_z']
|
||||||
server = GooglePlayAPI(debug=True)
|
server = GooglePlayAPI(debug=True)
|
||||||
|
|
||||||
try:
|
|
||||||
print('\nLogging in with email and password\n')
|
print('\nLogging in with email and password\n')
|
||||||
server.login(EMAIL, PASSWD, None, None)
|
server.login(EMAIL, PASSWD, None, None)
|
||||||
gsfId = server.gsfId
|
gsfId = server.gsfId
|
||||||
@ -18,7 +17,11 @@ try:
|
|||||||
server = GooglePlayAPI(debug=True)
|
server = GooglePlayAPI(debug=True)
|
||||||
server.login(None, None, gsfId, authSubToken)
|
server.login(None, None, gsfId, authSubToken)
|
||||||
|
|
||||||
apps = server.search('telegram', 1, None)
|
apps = server.search('telegram', 34, None)
|
||||||
|
|
||||||
|
print('nb_result: 34')
|
||||||
|
print('number of results: %d' % len(apps))
|
||||||
|
|
||||||
print('\nFound those apps:\n')
|
print('\nFound those apps:\n')
|
||||||
for a in apps:
|
for a in apps:
|
||||||
print(a['docId'])
|
print(a['docId'])
|
||||||
@ -34,6 +37,3 @@ try:
|
|||||||
print('\nGetting details for %s\n' % testApps[0])
|
print('\nGetting details for %s\n' % testApps[0])
|
||||||
bulk = server.bulkDetails(testApps)
|
bulk = server.bulkDetails(testApps)
|
||||||
print(bulk)
|
print(bulk)
|
||||||
except Exception as e:
|
|
||||||
print(str(e))
|
|
||||||
sys.exit(1)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user