本文整理匯總了Python中models.Request.gql方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.gql方法的具體用法?Python Request.gql怎麽用?Python Request.gql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Request
的用法示例。
在下文中一共展示了Request.gql方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get
# 需要導入模塊: from models import Request [as 別名]
# 或者: from models.Request import gql [as 別名]
def get(self, url):
ip = self.request.remote_addr #to prevent abuses, only a request every minute is served
request = Request.gql("where ip='%s'" % ip).get() #Look for request from the same IP address
if not request is None:
delta = request.is_allowed()
if delta > 0: #too little time has passed from the previous request
#self.error(408) #Timeout Error
self.response.set_status(408, "Your IP address has issued a request less than 1 min ago. Please wait %d seconds" % delta)
return
else:
request = Request(ip=ip, page_crawled=url)
request.save()
self.response.headers['Content-Type'] = 'application/json'
handler = CrawlerHandler()
site_image = memcache.get(url)
if site_image is None:
home_page = handler.start_crawling(url, MAX_PAGE_DEPTH, MAX_PAGES_TO_CRAWL, 0.01) #causes a little delay, but not too big (one 100th of a sec)
if home_page is None:
self.error(400) #Bad Request
return
else:
site_image = handler.page_graph(home_page)
memcache.set(url, site_image)
self.__responde(site_image)