def __search(self, keyword, search_type):
offset = 0
result_key = search_type + "s"
result = []
while True:
self.logger.info("search " + keyword + ", offset = " + str(offset))
params = {
"q": keyword,
"type": search_type,
"offset": offset,
"limit": 50
}
buf = BytesIO()
client = pycurl.Curl()
client.setopt(pycurl.URL, self.service_host +
"/v1/search" + "?" + urlencode(params))
client.setopt(pycurl.WRITEFUNCTION, buf.write)
client.perform()
client.close()
body = json.loads(buf.getvalue().decode("utf-8"))
buf.close()
if body[result_key]["total"] > 0:
for data in body[result_key]["items"]:
result.append(data)
if body[result_key]["total"] > \
body[result_key]["limit"] * (offset + 1):
offset = offset + 1
else:
break
self.logger.info("Done")
return result
评论列表
文章目录