add cover generator command
authorJan Szejko <janek37@gmail.com>
Fri, 7 Apr 2017 13:42:37 +0000 (15:42 +0200)
committerJan Szejko <janek37@gmail.com>
Fri, 7 Apr 2017 13:42:37 +0000 (15:42 +0200)
src/catalogue/management/commands/gencover.py [new file with mode: 0644]

diff --git a/src/catalogue/management/commands/gencover.py b/src/catalogue/management/commands/gencover.py
new file mode 100644 (file)
index 0000000..adb84ea
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django.core.management.base import BaseCommand
+
+from catalogue.models import Book
+from librarian.cover import DefaultEbookCover
+
+
+class Command(BaseCommand):
+    def add_arguments(self, parser):
+        parser.add_argument('slug')
+        parser.add_argument('size', type=int)
+
+    def handle(self, *args, **options):
+        slug = options['slug']
+        size = options['size']
+        wldoc = Book.objects.get(slug=slug).wldocument()
+        cover = DefaultEbookCover(wldoc.book_info, width=size)
+        cover.save('%s.jpg' % slug)