当前位置: 首页>>代码示例>>Python>>正文


Python Search.getResults方法代码示例

本文整理汇总了Python中Search.getResults方法的典型用法代码示例。如果您正苦于以下问题:Python Search.getResults方法的具体用法?Python Search.getResults怎么用?Python Search.getResults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Search的用法示例。


在下文中一共展示了Search.getResults方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: import Search [as 别名]
# 或者: from Search import getResults [as 别名]
    def post(self):
        """
        This receives a Query Object and performs a Search based on information from that Query.

        It then compares the results to the search_date and if they are deemed fresh, stores them.
        """
        
        new_search = Search()
        f = formatDatetime()

        q = db.get(self.request.get('key'))
        results = new_search.getResults(q.term, q.min, q.max, q.city)
        
        # Pull fresh listings from query, if they exist
        if q.fresh:
            fresh = q.fresh
        else: 
            fresh = FreshEntries()
            fresh.entries = [] # Store fresh listings here

        search_date = q.search_date
        latest_entry_time = search_date

        # Compare each entry datetime to the saved datetime
        for e in results:
            # Extract and format times from feed
            f_entry_time = f.craigslist_to_datetime(e.date)

            # Compute elapsed time since last search and this listing
            difference = f_entry_time - search_date

            # If entry is after the saved time, flag it as fresh
            if f_entry_time > search_date:

                # Check and see if this is the chronologically latest listing
                if f.craigslist_to_datetime(e.date) > latest_entry_time:
                    latest_entry_time = f.craigslist_to_datetime(e.date)

                entry = Entry(date = e.date, title = e.title, link = e.link)
                db.put(entry)
                fresh.entries.append(entry.key())
        db.put(fresh)

        # put back query with new search_date and new fresh listings
        q.search_date = latest_entry_time
        q.fresh = fresh
        db.put(q)
开发者ID:rcbm,项目名称:thriftfish,代码行数:49,代码来源:Fetch.py

示例2: get

# 需要导入模块: import Search [as 别名]
# 或者: from Search import getResults [as 别名]
    def get(self):
            
        if users.get_current_user():
            url = "/user"
            url_linktext = 'My Want List'
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'Login'

        f = formatDatetime()

        formatted_term = self.request.get('q')

        # handle spaces in query terms
        min = self.request.get('Min')
        max = self.request.get('Max')
        city = self.request.get('City')
        new_search = Search()
        try:
            results = new_search.getResults(formatted_term, min, max, city)
            if results:
                search_date = f.craigslist_to_datetime(results[0].date)
            else:
                search_date = datetime.now()

            template_values = {
                'search_date': search_date,
                'term': formatted_term,
                'min': min,
                'max': max,
                'city': city,
                'results': results,
                'url': url,
                'url_linktext': url_linktext,
                }
            path = os.path.join(os.path.dirname(__file__), '../static/html/search.html')
            self.response.out.write(template.render(path, template_values))
        except:
            self.response.out.write("Sorry, there was an error connecting to Craigslist.  Try checking your 'City' field, or possibly your internet connection, and try again.")
开发者ID:rcbm,项目名称:thriftfish,代码行数:41,代码来源:SearchPage.py


注:本文中的Search.getResults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。