X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/6a259b96cff47e1fd64cbfd6f3d1e1d8e8b6486c..24ef4f83129e718634e60e53a5c028e9fe3d7446:/apps/catalogue/management/commands/import_wl.py diff --git a/apps/catalogue/management/commands/import_wl.py b/apps/catalogue/management/commands/import_wl.py old mode 100755 new mode 100644 index 4f15cef8..8991c3a3 --- a/apps/catalogue/management/commands/import_wl.py +++ b/apps/catalogue/management/commands/import_wl.py @@ -19,8 +19,7 @@ WL_API = 'http://www.wolnelektury.pl/api/books/' class Command(BaseCommand): option_list = BaseCommand.option_list + ( - make_option('-q', '--quiet', action='store_false', dest='verbose', default=True, - help='Less output'), + make_option('-q', '--quiet', action='store_false', dest='verbose', default=True, help='Less output'), ) help = 'Imports XML files from WL.' @@ -49,20 +48,6 @@ class Command(BaseCommand): else: slugs[info.slug].append(b) - #~ conflicts = [] - #~ for slug, book_list in slugs.items(): - #~ if len(book_list) > 1: - #~ conflicts.append((slug, book_list)) - #~ if conflicts: - #~ print self.style.ERROR("There is more than one book " - #~ "with the same slug in dc:url. " - #~ "Merge or hide them before proceeding.") - #~ for slug, book_list in sorted(conflicts): - #~ print slug - #~ print "\n".join(b.slug for b in book_list) - #~ print - #~ return - book_count = 0 commit_args = { "author_name": 'Platforma', @@ -72,23 +57,23 @@ class Command(BaseCommand): if verbose: print 'Opening books list' - for book in json.load(urllib2.urlopen(WL_API))[:10]: + 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:"), + 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, - slug=info.slug, previous_book=previous_book, + 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 @@ -99,7 +84,5 @@ class Command(BaseCommand): book_count, ) print - transaction.commit() transaction.leave_transaction_management() -