本文整理汇总了Python中holmes.models.Page.add_page方法的典型用法代码示例。如果您正苦于以下问题:Python Page.add_page方法的具体用法?Python Page.add_page怎么用?Python Page.add_page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类holmes.models.Page
的用法示例。
在下文中一共展示了Page.add_page方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from holmes.models import Page [as 别名]
# 或者: from holmes.models.Page import add_page [as 别名]
def post(self):
post_data = loads(self.request.body)
url = post_data["url"]
score = float(post_data.get("score", self.application.config.DEFAULT_PAGE_SCORE))
result = yield Page.add_page(
self.db,
self.application.cache,
url,
score,
self.application.http_client.fetch,
self.application.event_bus.publish,
self.application.config,
)
created, url, result = result
if not created and result["reason"] == "invalid_url":
self.set_status(400, "Invalid url [%s]" % url)
self.write_json(
{"reason": "invalid_url", "url": url, "status": result["status"], "details": result["details"]}
)
return
if not created and result["reason"] == "redirect":
self.set_status(400, "Redirect URL [%s]" % url)
self.write_json({"reason": "redirect", "url": url, "effectiveUrl": result["effectiveUrl"]})
return
self.write(str(result))
self.finish()
示例2: enqueue
# 需要导入模块: from holmes.models import Page [as 别名]
# 或者: from holmes.models.Page import add_page [as 别名]
def enqueue(self, urls):
if not urls:
return
for url, score in urls:
Page.add_page(
self.db,
self.cache,
url,
score,
self.async_get_func,
self.publish,
self.config,
self.handle_page_added
)
self.wait_for_async_requests()
示例3: post
# 需要导入模块: from holmes.models import Page [as 别名]
# 或者: from holmes.models.Page import add_page [as 别名]
def post(self):
post_data = loads(self.request.body)
url = post_data['url']
score = float(post_data.get('score', self.application.config.DEFAULT_PAGE_SCORE))
result = yield Page.add_page(
self.db,
self.application.cache,
url,
score,
self.application.http_client.fetch,
self.application.event_bus.publish,
self.application.config
)
created, url, result = result
if not created and result['reason'] == 'invalid_url':
self.set_status(400, 'Invalid url [%s]' % url)
self.write_json({
'reason': 'invalid_url',
'url': url,
'status': result['status'],
'details': result['details']
})
return
if not created and result['reason'] == 'redirect':
self.set_status(400, 'Redirect URL [%s]' % url)
self.write_json({
'reason': 'redirect',
'url': url,
'effectiveUrl': result['effectiveUrl']
})
return
self.write(str(result))
self.finish()
示例4: post
# 需要导入模块: from holmes.models import Page [as 别名]
# 或者: from holmes.models.Page import add_page [as 别名]
def post(self):
post_data = loads(self.request.body)
url = post_data["url"]
score = float(post_data.get("score", self.application.config.DEFAULT_PAGE_SCORE))
result = yield Page.add_page(
self.db,
self.application.cache,
url,
score,
self.application.http_client.fetch,
self.application.event_bus.publish,
self.application.config,
self.application.girl,
self.application.default_violations_values,
self.application.violation_definitions,
)
created, url, result = result
if not created and result["reason"] == "invalid_url":
self.set_status(400, self._("Invalid url [%s]") % url)
self.write_json(
{"reason": "invalid_url", "url": url, "status": result["status"], "details": result["details"]}
)
return
if not created and result["reason"] == "redirect":
self.set_status(400, self._("Supplied URL is a redirect [%s]") % url)
self.write_json({"reason": "redirect", "url": url, "effectiveUrl": result["effectiveUrl"]})
return
yield self.application.cache.add_next_job_bucket(result, url)
self.write(str(result))
self.finish()