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


Python City.select方法代码示例

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


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

示例1: homepage

# 需要导入模块: from models import City [as 别名]
# 或者: from models.City import select [as 别名]
def homepage():
    query = request.args.get("postal_code", "84510")

    results = []

    for city in City.select().where(City.postal_code == query):
        results.append({"insee": city.insee, "name": city.name, "postal_code": city.postal_code, "label": city.label})

    return jsonify(results=results)
开发者ID:Debetux,项目名称:CodesPostauxAPI,代码行数:11,代码来源:views.py

示例2: main

# 需要导入模块: from models import City [as 别名]
# 或者: from models.City import select [as 别名]
def main():
    cities = City.select()
    city_dict = {}
    for city in cities:
        if city.parent is None:
            city_dict[city.id] = []
            city_dict[city.id].append({'id': city.id, 'name': city.name})
        else:
            city_dict[city.parent.id].append({'id': city.id, 'name': city.name})

    print(json.dumps(city_dict, ensure_ascii=False))
开发者ID:kmasaya,项目名称:lopet,代码行数:13,代码来源:city.makejs.py

示例3: save_to_db

# 需要导入模块: from models import City [as 别名]
# 或者: from models.City import select [as 别名]
    def save_to_db(self, dic):
        assert all(map(dic.has_key, ['title', 'original_price', 'price', 'detail', 'url'])),\
            "Information incomplete."
        
        url = dic['url']
        original_price = dic['original_price'].text.encode('utf8')
        price = dic['price'].text.encode('utf8')
        title = dic['title'].text # title is unicode
        detail = dic['detail'].renderContents(encoding='utf8')
        detail = utils.clean_detail(detail, self.home_url)
            
        # Data formatting & validation.
        try:
            original_price, price = map(lambda s: int(re.search(r'(\d+)', s).group()),
                                        [original_price, price])
        except TypeError:
            logging.error("Price conversion failed. Detailed info: %s", [original_price, price])
            return
        except AttributeError:
            logging.error("Regex failed on %s", [original_price, price])
            return
        
        if len(title) > 500 or len(title) < 10:
            logging.error("Title length too short or too long : %s", title)
            return
        
        if len(detail) < 20:
            logging.error("Detail too short. %s", detail)
            return

        # Save to db.
        try:
            site = Site.select(Site.q.url == self.home_url)
            assert(site.count() == 1), "%s not found or dups." % self.home_url
            
            title = utils.lstrip(title, [s.decode('utf8') for s in ('今日团购', '今日精选', ':')])
            title = title.strip()
            title='[%s] %s' % (site[0].name, title)
            
            city_name = self.index_urls[url]
            city = City.select(City.q.name == city_name.decode('utf8'))
            assert city.count() == 1, "%s not found or dups." % city_name
            cityID = city[0].id
            
            if Deal.select(AND(Deal.q.title == title, Deal.q.cityID == cityID)).count() > 0:
                logging.info("Title dups %s" % title)
                return
            deal = Deal(url=url, title=title, price=price, originalPrice=original_price,
                        detail=detail.decode('utf8'),cityID=cityID, siteID=site[0].id)
            logging.info('%s OK', url)
        except:
            # Simple handling for the moment.
            logging.error("Error occured while saving data : %s", sys.exc_info())
开发者ID:ViciousPotato,项目名称:groupon,代码行数:55,代码来源:basesite.py

示例4: city_list

# 需要导入模块: from models import City [as 别名]
# 或者: from models.City import select [as 别名]
def city_list():
    obj_list = City.select().order_by('name')
    return object_list('city_list.html', obj_list, "obj_list")
开发者ID:lite,项目名称:pinche,代码行数:5,代码来源:views.py


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