mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2025-06-21 15:58:22 +02:00
Add revues
This commit is contained in:
50
media/management/commands/import_marvel.py
Normal file
50
media/management/commands/import_marvel.py
Normal file
@ -0,0 +1,50 @@
|
||||
from argparse import FileType
|
||||
from sys import stdin
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
from media.models import Auteur, BD
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('input', nargs='?',
|
||||
type=FileType('r'),
|
||||
default=stdin,
|
||||
help="Marvel comic to be imported.")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
file = options["input"]
|
||||
revues = []
|
||||
for line in file:
|
||||
revues.append(line[:-1].split('|', 2))
|
||||
|
||||
print("Registering", len(revues), "Marvel comics")
|
||||
|
||||
imported = 0
|
||||
|
||||
for revue in revues:
|
||||
if len(revue) != 3:
|
||||
continue
|
||||
|
||||
title = revue[0]
|
||||
number = revue[1]
|
||||
authors = [Auteur.objects.get_or_create(name=n)[0]
|
||||
for n in revue[2].split('|')]
|
||||
bd = BD.objects.create(
|
||||
title=title,
|
||||
subtitle=number,
|
||||
side_identifier="{:.3} {:.3} {:0>2}"
|
||||
.format(authors[0].name.upper(),
|
||||
title.upper(),
|
||||
number),
|
||||
)
|
||||
|
||||
bd.authors.set(authors)
|
||||
bd.save()
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
"Comic imported"))
|
||||
imported += 1
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
"{count} comics imported".format(count=imported)))
|
58
media/management/commands/import_revues.py
Normal file
58
media/management/commands/import_revues.py
Normal file
@ -0,0 +1,58 @@
|
||||
from argparse import FileType
|
||||
from sys import stdin
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
from media.models import Revue
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('input', nargs='?',
|
||||
type=FileType('r'),
|
||||
default=stdin,
|
||||
help="Revues to be imported.")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
file = options["input"]
|
||||
revues = []
|
||||
for line in file:
|
||||
revues.append(line[:-1].split('|'))
|
||||
|
||||
print("Registering", len(revues), "revues")
|
||||
|
||||
imported = 0
|
||||
|
||||
for revue in revues:
|
||||
if len(revue) != 5:
|
||||
continue
|
||||
|
||||
title = revue[0]
|
||||
number = revue[1]
|
||||
day = revue[2]
|
||||
if not day:
|
||||
day = None
|
||||
month = revue[3]
|
||||
if not month:
|
||||
month = None
|
||||
year = revue[4]
|
||||
if not year:
|
||||
year = None
|
||||
revue, created = Revue.objects.get_or_create(
|
||||
title=title,
|
||||
number=number.replace('*', ''),
|
||||
year=year,
|
||||
month=month,
|
||||
day=day,
|
||||
double=number.endswith('*'),
|
||||
)
|
||||
|
||||
if not created:
|
||||
self.stderr.write(self.style.WARNING(
|
||||
"One revue was already imported. Skipping..."))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
"Revue imported"))
|
||||
imported += 1
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
"{count} revues imported".format(count=imported)))
|
Reference in New Issue
Block a user