<commit_before># -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © <NAME>. See NOTICE for more information.
#
from django.core.management.base import BaseCommand

from catalogue.models import Book
from librarian.cover import make_cover


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('slug')
        parser.add_argument('--width', type=int)
        parser.add_argument('--height', type=int)
        parser.add_argument('--bleed', action='store_true')

    def handle(self, *args, **options):
        slug = options['slug']
        width = options['width']
        height = options.get('height')
        bleed = 20 if options['bleed'] else 0
        wldoc = Book.objects.get(slug=slug).wldocument()
        cover = make_cover(wldoc.book_info, width=width, height=height, bleed=bleed)
        cover.save('%s.jpg' % slug)<commit_msg>add option to choose cover class<commit_after># -*- coding: utf-8 -*-
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © <NAME>. See NOTICE for more information.
#
from django.core.management.base import BaseCommand

from catalogue.models import Book
from librarian.cover import make_cover


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('slug')
        parser.add_argument('--width', type=int)
        parser.add_argument('--height', type=int)
        parser.add_argument('--bleed', action='store_true')
        parser.add_argument('--cover-class', type=str)

    def handle(self, *args, **options):
        slug = options['slug']
        width = options['width']
        height = options.get('height')
        cover_class = options.get('cover_class')
        bleed = 20 if options['bleed'] else 0
        wldoc = Book.objects.get(slug=slug).wldocument()
        kwargs = {}
        if cover_class:
            kwargs['cover_class'] = cover_class
        cover = make_cover(wldoc.book_info, width=width, height=height, bleed=bleed, **kwargs)
        cover.save('%s.jpg' % slug)
{'fraction_non_alphanumeric': 0.13086770981507823, 'fraction_numerical': 0.00474158368895211, 'mean_word_length': 3.245472837022133, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '405229', 'n_tokens_mistral': 642, 'n_tokens_neox': 628, 'n_words': 160}