1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django.core.management.base import BaseCommand
7 from django.utils.timezone import localtime
9 from catalogue.models import Book
10 from isbn.utils import isbn_data, FORMATS, FORMATS_WITH_CHILDREN
13 class Command(BaseCommand):
15 def handle(self, *args, **options):
16 slugs = [line.strip() for line in sys.stdin]
17 writer = csv.writer(sys.stdout)
18 all_books = Book.objects.filter(slug__in=slugs)
19 books_without_children = all_books.filter(children=None)
20 for file_format in FORMATS:
21 if file_format in FORMATS_WITH_CHILDREN:
24 books = books_without_children
26 date = localtime(book.created_at).date().isoformat()
27 data = isbn_data(book.wldocument(), file_format)
37 data['corporate_name'],
39 data['edition_number'],
41 data['product_form_detail'],
46 writer.writerow([s.encode('utf-8') for s in row])