diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-19 23:15:01 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-19 23:15:01 (GMT) |
commit | e1d853c457d77d1f36ad211c85dc28a8833cd6cd (patch) | |
tree | 3668b67ab4d13e102d777e3e0e67d59ce16bd668 | |
parent | 0176bc873cb1b46a1ebf277fe1f138f26bd95e31 (diff) |
data migration.
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | program/fixtures/hosts.yaml | 520 | ||||
-rw-r--r-- | program/fixtures/shows.yaml | 3 | ||||
-rw-r--r-- | program/management/commands/importhosts.py | 34 | ||||
-rw-r--r-- | program/management/commands/importprogramslots.py | 91 | ||||
-rw-r--r-- | program/management/commands/importshows.py | 62 |
6 files changed, 189 insertions, 522 deletions
@@ -1,4 +1,3 @@ -* data migration * current/next/after next show view * day schedule view * week schedule view diff --git a/program/fixtures/hosts.yaml b/program/fixtures/hosts.yaml index b26b2e5..4cccf3a 100644 --- a/program/fixtures/hosts.yaml +++ b/program/fixtures/hosts.yaml @@ -1,524 +1,4 @@ - model: program.host - pk: 0 - fields: - name: N. N. -- model: program.host pk: 1 fields: name: Musikredaktion -- model: program.host - pk: 2 - fields: - name: Franz Schopper -- model: program.host - pk: 3 - fields: - name: Michael Haberz -- model: program.host - pk: 4 - fields: - name: Tarek Al-Ubaidi -- model: program.host - pk: 5 - fields: - name: Otmar Klammer -- model: program.host - pk: 6 - fields: - name: Burschi Wachsmann -- model: program.host - pk: 7 - fields: - name: Rupert Kittinger -- model: program.host - pk: 8 - fields: - name: Frant Hofer & Literaturgruppe 112/31 -- model: program.host - pk: 9 - fields: - name: Martin Schemitsch -- model: program.host - pk: 10 - fields: - name: Dr. Johannes Schmidt -- model: program.host - pk: 11 - fields: - name: Amos Schmidt -- model: program.host - pk: 12 - fields: - name: Franz 'Fratl' Hofer -- model: program.host - pk: 13 - fields: - name: Moke Klengel -- model: program.host - pk: 14 - fields: - name: Claudia Holzer -- model: program.host - pk: 15 - fields: - name: Gerhard Buchinger -- model: program.host - pk: 16 - fields: - name: Judith Wlaschitz -- model: program.host - pk: 17 - fields: - name: Hannes Knierzinger -- model: program.host - pk: 18 - fields: - name: Gerhard Gutschi -- model: program.host - pk: 19 - fields: - name: Angelika Hofmann -- model: program.host - pk: 20 - fields: - name: Gisi Linschinger -- model: program.host - pk: 21 - fields: - name: Andreas Lehrner -- model: program.host - pk: 22 - fields: - name: Georg Brenner -- model: program.host - pk: 23 - fields: - name: Leo Kühberger -- model: program.host - pk: 24 - fields: - name: Dr. Roman Koller -- model: program.host - pk: 25 - fields: - name: Anita Inzinger -- model: program.host - pk: 26 - fields: - name: Jetter Musger -- model: program.host - pk: 27 - fields: - name: Mike Schneider -- model: program.host - pk: 28 - fields: - name: Reni Hofmüller -- model: program.host - pk: 29 - fields: - name: Heimo Ranzenbacher -- model: program.host - pk: 30 - fields: - name: Nara Niemetz -- model: program.host - pk: 31 - fields: - name: Harald Weidacher -- model: program.host - pk: 32 - fields: - name: Mag. Vilja Neuwirth -- model: program.host - pk: 33 - fields: - name: Sirin Sivan -- model: program.host - pk: 34 - fields: - name: Erich Zib -- model: program.host - pk: 35 - fields: - name: Popkorn / KIM -- model: program.host - pk: 36 - fields: - name: Benedikt Kaiser -- model: program.host - pk: 37 - fields: - name: Romeo Ried -- model: program.host - pk: 38 - fields: - name: Florian Raggam -- model: program.host - pk: 39 - fields: - name: Erich Jägger -- model: program.host - pk: 40 - fields: - name: Wolfram Märzendorfer -- model: program.host - pk: 41 - fields: - name: Water Lang -- model: program.host - pk: 42 - fields: - name: MMag. Tünde Primus-Kövendi -- model: program.host - pk: 43 - fields: - name: Georg Wissa -- model: program.host - pk: 44 - fields: - name: Robert Suchar -- model: program.host - pk: 45 - fields: - name: Wolfgang Schmidt -- model: program.host - pk: 46 - fields: - name: Romana Scheiblmaier -- model: program.host - pk: 47 - fields: - name: Andreas Polz -- model: program.host - pk: 48 - fields: - name: Rita Obergschwandner -- model: program.host - pk: 49 - fields: - name: Josef J. Schmelz-Ziringer -- model: program.host - pk: 50 - fields: - name: Lonestaer / KIM -- model: program.host - pk: 51 - fields: - name: Ionel Mircea Popi -- model: program.host - pk: 52 - fields: - name: Cristina Popi -- model: program.host - pk: 53 - fields: - name: Dipl.-Päd. DI Markus Ehrenpaat -- model: program.host - pk: 54 - fields: - name: Helga Maria Lang -- model: program.host - pk: 55 - fields: - name: Redaktion A -- model: program.host - pk: 56 - fields: - name: Thomas Kerekes -- model: program.host - pk: 57 - fields: - name: Moser -- model: program.host - pk: 58 - fields: - name: Leuprecht -- model: program.host - pk: 59 - fields: - name: Handler -- model: program.host - pk: 60 - fields: - name: Joeller -- model: program.host - pk: 61 - fields: - name: Märzendorfer -- model: program.host - pk: 62 - fields: - name: Christian Berger (aufdraht) -- model: program.host - pk: 63 - fields: - name: bright night light -- model: program.host - pk: 64 - fields: - name: furth van der haam -- model: program.host - pk: 65 - fields: - name: neonlike -- model: program.host - pk: 66 - fields: - name: saus'n'browse -- model: program.host - pk: 67 - fields: - name: Peter Schabler -- model: program.host - pk: 68 - fields: - name: Sabine Schabler-Urban -- model: program.host - pk: 69 - fields: - name: Martin Gupper -- model: program.host - pk: 70 - fields: - name: Lila -- model: program.host - pk: 71 - fields: - name: Marco Schretter -- model: program.host - pk: 72 - fields: - name: Daniel Mayrhofer -- model: program.host - pk: 73 - fields: - name: Dompreh Kwesi -- model: program.host - pk: 74 - fields: - name: DJ Selchfleisch -- model: program.host - pk: 75 - fields: - name: Robert Lepenik -- model: program.host - pk: 76 - fields: - name: Markus -- model: program.host - pk: 77 - fields: - name: Johanna -- model: program.host - pk: 78 - fields: - name: Thomas Dörflinger -- model: program.host - pk: 79 - fields: - name: Anita Hofer -- model: program.host - pk: 80 - fields: - name: Wolfram Scheucher -- model: program.host - pk: 81 - fields: - name: Martina Pusterhofer -- model: program.host - pk: 82 - fields: - name: Andrei Reyes Huamantico -- model: program.host - pk: 83 - fields: - name: Sebastian Zhuber-Okrog -- model: program.host - pk: 84 - fields: - name: Daniela List -- model: program.host - pk: 85 - fields: - name: Thomas Fassler -- model: program.host - pk: 86 - fields: - name: Manfred Krejcik -- model: program.host - pk: 87 - fields: - name: Mezopotamya Team -- model: program.host - pk: 88 - fields: - name: Adrian C.S. Kainz -- model: program.host - pk: 89 - fields: - name: Francesco Königsberger -- model: program.host - pk: 90 - fields: - name: kat.ee a.k.a. Katarina Pekic -- model: program.host - pk: 91 - fields: - name: fabsab a.k.a. Sabine Omann -- model: program.host - pk: 92 - fields: - name: Flo Müller -- model: program.host - pk: 93 - fields: - name: Max Höfler -- model: program.host - pk: 94 - fields: - name: Livia Sellin -- model: program.host - pk: 95 - fields: - name: Christine Jeindl -- model: program.host - pk: 96 - fields: - name: Martin Brunner -- model: program.host - pk: 97 - fields: - name: Initiative Minderheiten / Radio Orange -- model: program.host - pk: 98 - fields: - name: Timo Scheuer und Rene Schuster für Vereine aus Graz -- model: program.host - pk: 99 - fields: - name: David Donnerer -- model: program.host - pk: 100 - fields: - name: Thomas Burgstaller -- model: program.host - pk: 101 - fields: - name: Martin Dopler -- model: program.host - pk: 102 - fields: - name: Patrick Kern -- model: program.host - pk: 103 - fields: - name: Klaus, Sigi und David Lax -- model: program.host - pk: 104 - fields: - name: Alexander Gutmann -- model: program.host - pk: 105 - fields: - name: Claudia Klemm -- model: program.host - pk: 106 - fields: - name: Christian Stani -- model: program.host - pk: 107 - fields: - name: Student*innen der Universität Graz -- model: program.host - pk: 108 - fields: - name: Gruppe rund um Roman Schweidlenka -- model: program.host - pk: 109 - fields: - name: Joseph Dim -- model: program.host - pk: 110 - fields: - name: Felix von Bally -- model: program.host - pk: 111 - fields: - name: Die Radio Helsinki Filmredaktion -- model: program.host - pk: 112 - fields: - name: Teresa Falk -- model: program.host - pk: 113 - fields: - name: Stefan Schmitzer -- model: program.host - pk: 114 - fields: - name: Institut für Volksmusikforschung an der Universität für Musik und darstellende Kust Wien -- model: program.host - pk: 115 - fields: - name: Gert Enzi -- model: program.host - pk: 116 - fields: - name: Wolfgang Zeyringer -- model: program.host - pk: 117 - fields: - name: Ulli Stranka -- model: program.host - pk: 118 - fields: - name: Thomas Kapun -- model: program.host - pk: 119 - fields: - name: Leni Kastl -- model: program.host - pk: 120 - fields: - name: gender frequenz Redaktion -- model: program.host - pk: 121 - fields: - name: helga im Namen der spacefemfm frauen -- model: program.host - pk: 122 - fields: - name: Alex Meyer -- model: program.host - pk: 123 - fields: - name: Aviv Russ -- model: program.host - pk: 124 - fields: - name: Nico, Martin, Martin -- model: program.host - pk: 125 - fields: - name: Maria Schörgel -- model: program.host - pk: 126 - fields: - name: Alex Sieber -- model: program.host - pk: 127 - fields: - name: Günther Polanz -- model: program.host - pk: 128 - fields: - name: (vorstadttheater soundsystem) -- model: program.host - pk: 129 - fields: - name: atTRaktiv -- model: program.host - pk: 130 - fields: - name: Günther Friesinger
\ No newline at end of file diff --git a/program/fixtures/shows.yaml b/program/fixtures/shows.yaml index 0661ba9..f520b26 100644 --- a/program/fixtures/shows.yaml +++ b/program/fixtures/shows.yaml @@ -1,5 +1,5 @@ - model: program.show - pk: 0 + pk: 1 fields: hosts: [1] broadcastformat: 3 @@ -7,3 +7,4 @@ slug: musikprogramm description: Unmoderiertes Musikprogramm short_description: Unmoderiertes Musikprogramm + email: musikredaktion@helsinki.at diff --git a/program/management/commands/importhosts.py b/program/management/commands/importhosts.py new file mode 100644 index 0000000..0f1b154 --- /dev/null +++ b/program/management/commands/importhosts.py @@ -0,0 +1,34 @@ +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].decode('latin1').encode('utf8').split(','): + host = Host(name=macher.strip()) + host.save() + + counter += 1 + + cursor.close() + connection.close() + + print '%i hosts imported' % counter
\ No newline at end of file diff --git a/program/management/commands/importprogramslots.py b/program/management/commands/importprogramslots.py new file mode 100644 index 0000000..904036e --- /dev/null +++ b/program/management/commands/importprogramslots.py @@ -0,0 +1,91 @@ +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, ProgramSlot, 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 programslots 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.decode('latin1').encode('utf8')) + + 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) + + programslot = ProgramSlot(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, tstart=tstart, tend=tend, until=letzter_termin) + programslot.save() + counter += 1 + except ObjectDoesNotExist: + print 'show with name "%s" not found' % titel + except KeyError: + print 'rhythmus "%i" is not supported for sendung "%s"' % (rhytmus, 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 = titel.decode('latin1').encode('utf8')[:-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) + + programslot = ProgramSlot(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, tstart=tstart, tend=tend, until=letzter_termin, is_repetition=True) + programslot.save() + counter += 1 + except ObjectDoesNotExist: + print 'show with name "%s" not found' % titel + except KeyError: + print 'rhythmus "%i" is not supported for sendung "%s"' % (rhytmus, titel) + + cursor.close() + connection.close() + + print '%i programslots imported' % counter diff --git a/program/management/commands/importshows.py b/program/management/commands/importshows.py new file mode 100644 index 0000000..71eb6fb --- /dev/null +++ b/program/management/commands/importshows.py @@ -0,0 +1,62 @@ +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 clean_html, 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.decode('latin1').encode('utf8')) + beschreibung = clean_html(beschreibung.decode('latin1').encode('utf8')) + + slug = slugify(titel) + + hosts = [] + + for macher in macher.decode('latin1').encode('utf8').split(','): + try: + host = Host.objects.get(name=macher.strip()) + hosts.append(host) + except MultipleObjectsReturned: + print 'multiple hosts with name "%s" found' % macher + except ObjectDoesNotExist: + print 'host with name "%s" not found' % macher + + try: + show = Show.objects.get(name=titel) + print 'sendung "%s" already imported as show "%s"' % (titel, show) + except ObjectDoesNotExist: + show = Show(broadcastformat=TALK, name=titel, slug=slug, short_description='FIXME', description=beschreibung) + show.save() + counter += 1 + + for h in hosts: + show.hosts.add(h) + show.save() + + cursor.close() + connection.close() + + print '%i shows imported' % counter |