本文整理汇总了Python中catalogue.models.Book.import_xml_text方法的典型用法代码示例。如果您正苦于以下问题:Python Book.import_xml_text方法的具体用法?Python Book.import_xml_text怎么用?Python Book.import_xml_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类catalogue.models.Book
的用法示例。
在下文中一共展示了Book.import_xml_text方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from catalogue.models import Book [as 别名]
# 或者: from catalogue.models.Book import import_xml_text [as 别名]
def handle(self, *args, **options):
self.style = color_style()
verbose = options.get('verbose')
# Start transaction management.
transaction.enter_transaction_management()
if verbose:
print 'Reading currently managed files (skipping hidden ones).'
slugs = defaultdict(list)
for b in Book.objects.exclude(slug__startswith='.').all():
if verbose:
print b.slug
text = b.materialize().encode('utf-8')
try:
info = BookInfo.from_string(text)
except (ParseError, ValidationError):
pass
else:
slugs[info.slug].append(b)
book_count = 0
commit_args = {
"author_name": 'Platforma',
"description": 'Automatycznie zaimportowane z Wolnych Lektur',
"publishable": True,
}
if verbose:
print 'Opening books list'
for book in json.load(urllib2.urlopen(WL_API)):
book_detail = json.load(urllib2.urlopen(book['href']))
xml_text = urllib2.urlopen(book_detail['xml']).read()
info = BookInfo.from_string(xml_text)
previous_books = slugs.get(info.slug)
if previous_books:
if len(previous_books) > 1:
print self.style.ERROR("There is more than one book "
"with slug %s:"),
previous_book = previous_books[0]
comm = previous_book.slug
else:
previous_book = None
comm = '*'
print book_count, info.slug , '-->', comm
Book.import_xml_text(xml_text, title=info.title[:255],
slug=info.slug[:128], previous_book=previous_book,
commit_args=commit_args)
book_count += 1
# Print results
print
print "Results:"
print "Imported %d books from WL:" % (
book_count, )
print
transaction.commit()
transaction.leave_transaction_management()