當前位置: 首頁>>代碼示例>>Python>>正文


Python Request.gql方法代碼示例

本文整理匯總了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) 
開發者ID:mlarocca,項目名稱:V-rawler,代碼行數:36,代碼來源:v-rawler.py


注:本文中的models.Request.gql方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。