本文整理汇总了Python中models.Item.create方法的典型用法代码示例。如果您正苦于以下问题:Python Item.create方法的具体用法?Python Item.create怎么用?Python Item.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import create [as 别名]
def save_item(self, item_dict):
try:
item = Item.create(**item_dict)
item = item.to_unicode()
except peewee.IntegrityError as e:
print type(e), e
item = self.query_db(item_dict['name'])
return item
示例2: save_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import create [as 别名]
def save_item(self, item_dict):
# if no example, do not save to db, but if added to xml, save it to db.
if item_dict['example']:
try:
item = Item.create(**item_dict)
except peewee.IntegrityError as e:
print type(e), e
item = self.query_db(item_dict['name'])
else:
item = Item(**item_dict)
return item
示例3: len
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import create [as 别名]
return
log.debug("%s - %d entries in %fs" % (netloc, len(entries),time.time()-now))
now = time.time()
records = 0
now = time.time()
ix = open_dir(settings.index)
writer = AsyncWriter(ix)
for entry in entries:
try:
item = Item.get(guid = entry['guid'])
except Item.DoesNotExist:
item = Item.create(**entry)
records += 1
if len(entry['html']):
soup = BeautifulSoup(entry['html'], settings.fetcher.parser)
plaintext = ''.join(soup.find_all(text=True))
writer.add_document(
id = item.id,
guid = unicode(item.guid),
title = entry['title'],
text = plaintext,
when = datetime.datetime.utcfromtimestamp(item.when)
)
hrefs = get_link_references(soup)
else:
示例4: save
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import create [as 别名]
def save(item_dict):
item = Item.create(**item_dict)
return item
示例5: save
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import create [as 别名]
def save(self, item_dict):
if item_dict['example']:
self.item = Item.create(**item_dict)
else:
self.item = Item(**item_dict)