feat: app inside project with custom command

This commit is contained in:
eneller
2025-03-16 15:31:45 +01:00
parent 52998fa280
commit 0589148b6f
14 changed files with 73 additions and 21 deletions

View File

@@ -0,0 +1,20 @@
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from epub2go.convert import get_all_books, Book, allbooks_url
import pickle, os
class Command(BaseCommand):
help = "Download the Book List"
filepath = os.path.join(settings.MEDIA_ROOT, 'books.pkl')
def handle(self, *args, **options):
try:
books = get_all_books()
except:
raise CommandError('Failed to get Book list from %s', allbooks_url)
try:
with open(self.filepath, 'wb') as file:
pickle.dump(books,file)
except:
raise CommandError(f'Failed to save pickle file. Did you create {settings.MEDIA_ROOT} ?')