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