本文整理汇总了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)
示例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))
示例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())
示例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")