diff --git a/program/management/commands/cleanup_defaultshow.py b/program/management/commands/cleanup_defaultshow.py deleted file mode 100644 index f27c4093e31f5838c39799b9eab745e6a94a6a9b..0000000000000000000000000000000000000000 --- a/program/management/commands/cleanup_defaultshow.py +++ /dev/null @@ -1,22 +0,0 @@ -from django.core.management.base import NoArgsCommand -from django.db import transaction - -from program.models import Show, TimeSlot, Schedule - - -class Command(NoArgsCommand): - help = 'removes default shows without note' - - @transaction.commit_manually - def handle_noargs(self, **options): - - default_show = Show.objects.get(pk=1) - try: - TimeSlot.objects.filter(show=default_show, note__isnull=True).delete() - for schedule in Schedule.objects.filter(show=default_show): - if schedule.timeslots.count() == 0: - schedule.delete() - except: - transaction.rollback() - else: - transaction.commit() \ No newline at end of file diff --git a/program/management/commands/importhosts.py b/program/management/commands/importhosts.py deleted file mode 100644 index a0b92923d7f722aaa888edddd8528706dcf82b1e..0000000000000000000000000000000000000000 --- a/program/management/commands/importhosts.py +++ /dev/null @@ -1,35 +0,0 @@ -from django.core.management.base import NoArgsCommand - -import MySQLdb - -from program.models import Host - -USER = 'helsinki' -PASSWD = 'helsinki' -DB = 'helsinki' - - -class Command(NoArgsCommand): - help = 'Import hosts from current program' - - def handle_noargs(self, **options): - connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB) - cursor = connection.cursor() - - cursor.execute("""SELECT DISTINCT macher -FROM sendungen -WHERE letzter_termin > current_date AND macher != '' AND titel NOT LIKE 'Musikprogramm'""") - - counter = 0 - - for row in cursor.fetchall(): - for macher in row[0].split(','): - host = Host(name=macher.strip()) - host.save() - - counter += 1 - - cursor.close() - connection.close() - - self.stdout.write(self.style.SUCCESS, F'{counter} hosts imported') diff --git a/program/management/commands/importnotes.py b/program/management/commands/importnotes.py deleted file mode 100644 index 91476e6f9e094fedda2a5bd1f092ab57aae06531..0000000000000000000000000000000000000000 --- a/program/management/commands/importnotes.py +++ /dev/null @@ -1,65 +0,0 @@ -from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, ValidationError -from django.core.management.base import NoArgsCommand -from django.utils.html import strip_tags - -import MySQLdb - -from program.models import Note, Show, TimeSlot - -USER = 'helsinki' -PASSWD = 'helsinki' -DB = 'helsinki' - - -class Command(NoArgsCommand): - help = 'Import notes from current program' - - def handle_noargs(self, **options): - connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB) - cursor = connection.cursor() - - cursor.execute("""SELECT n.titel, n.datum, s.titel, n.notiz -FROM notizen AS n JOIN sendungen AS s ON n.sendung_id=s.id -WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_date)""") - - counter = 0 - for ntitel, datum, stitel, notiz in cursor.fetchall(): - ntitel = strip_tags(ntitel) if ntitel else strip_tags(stitel) - stitel = strip_tags(stitel) - notiz = strip_tags(notiz) - - if stitel.endswith('(Wiederholung)'): - stitel = stitel[:-15] - - if datum: - year, month, day = datum.year, datum.month, datum.day - try: - show = Show.objects.get(name=stitel) - except ObjectDoesNotExist: - self.stdout.write(self.style.WARNING, f'show with name "{stitel}" not found') - else: - try: - timeslot = TimeSlot.objects.get(schedule__show=show, start__year=year, start__month=month, - start__day=day) - except ObjectDoesNotExist: - self.stdout.write(self.style.WARNING, f'no timeslot found for sendung "{stitel}" and datum "{datum}"') - except MultipleObjectsReturned: - self.stdout.write(self.style.WARNING, f'multiple timeslots found for sendung "{stitel}" and datum "{datum}"') - else: - note = Note(timeslot=timeslot, title=ntitel, content=notiz) - try: - note.validate_unique() - except ValidationError: - self.stdout.write(self.style.WARNING, f'note already imported for show "{stitel}" and datum "{datum}"') - else: - try: - note.save() - except: - self.stdout.write(self.style.ERROR, f'could not save note "{ntitel}" for show "{stitel}" and datum "{datum}"') - else: - counter += 1 - - cursor.close() - connection.close() - - self.stdout.write(self.style.SUCCESS, f'{counter} notes imported') diff --git a/program/management/commands/importprogramslots.py b/program/management/commands/importprogramslots.py deleted file mode 100644 index 8ce8a2bdd80084202bc75e37feedfff5098fea47..0000000000000000000000000000000000000000 --- a/program/management/commands/importprogramslots.py +++ /dev/null @@ -1,98 +0,0 @@ -from django.core.exceptions import ObjectDoesNotExist -from django.core.management.base import NoArgsCommand -from django.utils.html import strip_tags - -from datetime import time -import MySQLdb - -from program.models import Show, Schedule, RRule - -USER = 'helsinki' -PASSWD = 'helsinki' -DB = 'helsinki' - -RRULES = { - 0: RRule.objects.get(pk=1), - 7: RRule.objects.get(pk=3), - 14: RRule.objects.get(pk=4), - 28: RRule.objects.get(pk=5) -} - - -class Command(NoArgsCommand): - help = 'Import schedules from the current program' - - def handle_noargs(self, **options): - connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB) - cursor = connection.cursor() - - cursor.execute("""SELECT titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin -FROM sendungen -WHERE letzter_termin > current_date AND titel NOT LIKE 'Musikprogramm' AND titel NOT LIKE '%%(Wiederholung)'""") - - counter = 0 - - for titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin in cursor.fetchall(): - titel = strip_tags(titel) - - hours, seconds = divmod(beginn.seconds, 3600) - minutes, seconds = divmod(seconds, 60) - tstart = time(hour=hours, minute=minutes, second=seconds) - - hours, seconds = divmod(ende.seconds, 3600) - minutes, seconds = divmod(seconds, 60) - tend = time(hour=hours, minute=minutes, second=seconds) - - try: - rrule = RRULES[rhytmus] - try: - show = Show.objects.get(name=titel) - except ObjectDoesNotExist: - self.stdout.write(self.style.NOTICE, f'show with name "{titel}" not found') - else: - schedule = Schedule(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, - tstart=tstart, tend=tend, until=letzter_termin) - try: - schedule.save() - counter += 1 - except: - pass - except KeyError: - self.stdout.write(self.style.NOTICE, f'rhythmus "{rhytmus}" is not supported for sendung "{titel}"') - - cursor.execute("""SELECT titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin -FROM sendungen -WHERE letzter_termin > current_date AND titel LIKE '%%(Wiederholung)'""") - - for titel, beginn, ende, erster_termin, letzter_termin, rhytmus, termin in cursor.fetchall(): - titel = strip_tags(titel[:-15]) - - hours, seconds = divmod(beginn.seconds, 3600) - minutes, seconds = divmod(seconds, 60) - tstart = time(hour=hours, minute=minutes, second=seconds) - - hours, seconds = divmod(ende.seconds, 3600) - minutes, seconds = divmod(seconds, 60) - tend = time(hour=hours, minute=minutes, second=seconds) - - try: - rrule = RRULES[rhytmus] - try: - show = Show.objects.get(name=titel) - except ObjectDoesNotExist: - self.stdout.write(self.style.WARNING, f'show with name "{titel}" not found') - else: - schedule = Schedule(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, - tstart=tstart, tend=tend, until=letzter_termin, is_repetition=True) - try: - schedule.save() - counter += 1 - except: - pass - except KeyError: - self.stdout.write(self.style.WARNING, f'rhythmus "{rhytmus}" is not supported for sendung "{titel}"') - - cursor.close() - connection.close() - - self.stdout.write(self.style.SUCCESS, f'{counter} schedules imported') diff --git a/program/management/commands/importshows.py b/program/management/commands/importshows.py deleted file mode 100644 index cff3d434d8b29ab7692c1da57e2cb93292020e27..0000000000000000000000000000000000000000 --- a/program/management/commands/importshows.py +++ /dev/null @@ -1,69 +0,0 @@ -from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned -from django.core.management.base import NoArgsCommand -from django.template.defaultfilters import slugify -from django.utils.html import strip_tags - -import MySQLdb - -from program.models import BroadcastFormat, Host, Show - -USER = 'helsinki' -PASSWD = 'helsinki' -DB = 'helsinki' - -TALK = BroadcastFormat.objects.get(pk=1) - - -class Command(NoArgsCommand): - help = 'Import shows from the current program' - - def handle_noargs(self, **options): - connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB) - cursor = connection.cursor() - - cursor.execute("""SELECT titel, beschreibung, web, macher -FROM sendungen -WHERE letzter_termin > current_date AND titel NOT LIKE 'Musikprogramm' AND titel NOT LIKE '%%(Wiederholung)' -ORDER BY titel, beginn, ende""") - - counter = 0 - - for titel, beschreibung, web, macher in cursor.fetchall(): - titel = strip_tags(titel) - beschreibung = strip_tags(beschreibung) - - slug = slugify(titel) - - hosts = [] - - for macher in macher.split(','): - macher = macher.strip() - try: - host = Host.objects.get(name=macher) - except MultipleObjectsReturned: - self.stdout.write(self.style.NOTICE, f'multiple hosts with name "{macher}" found') - except ObjectDoesNotExist: - self.stdout.write(self.style.NOTICE, f'host with name "{macher}" not found') - else: - hosts.append(host) - - try: - show = Show.objects.get(name=titel) - self.stdout.write(self.style.NOTICE, f'sendung "{titel}" already imported as show "{show}"') - except ObjectDoesNotExist: - show = Show(broadcastformat=TALK, name=titel, slug=slug, short_description='FIXME', - description=beschreibung) - try: - show.save() - counter += 1 - except: - self.stdout.write(self.style.NOTICE, f'sendung "{titel}" could not be imported') - else: - for h in hosts: - show.hosts.add(h) - show.save() - - cursor.close() - connection.close() - - self.stdout.write(self.style.SUCCESS, f'{counter} shows imported')