summaryrefslogtreecommitdiff
path: root/program/management/commands
diff options
context:
space:
mode:
authorJohannes Raggam <raggam-nl@adm.at>2011-03-26 19:36:39 (GMT)
committerJohannes Raggam <raggam-nl@adm.at>2011-03-26 19:36:39 (GMT)
commit1f384ccf609e4d8cea4ac15c789d044ab6fa86f7 (patch)
treecabede5815519adcce80cfa5aeee239873221b11 /program/management/commands
parent5504c0d926aabb2017e547bfbfbcf986ce5ee037 (diff)
creating an egg pt2
Diffstat (limited to 'program/management/commands')
-rw-r--r--program/management/commands/__init__.py2
-rw-r--r--program/management/commands/importhosts.py34
-rw-r--r--program/management/commands/importnotes.py62
-rw-r--r--program/management/commands/importprogramslots.py96
-rw-r--r--program/management/commands/importshows.py67
5 files changed, 0 insertions, 261 deletions
diff --git a/program/management/commands/__init__.py b/program/management/commands/__init__.py
deleted file mode 100644
index 3aa4ca5..0000000
--- a/program/management/commands/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
-__author__ = 'ers'
- \ 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 39a8afd..0000000
--- a/program/management/commands/importhosts.py
+++ /dev/null
@@ -1,34 +0,0 @@
-from django.core.management.base import NoArgsCommand
-
-import MySQLdb
-
-from helsinki.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()
-
- print '%i hosts imported' % counter
diff --git a/program/management/commands/importnotes.py b/program/management/commands/importnotes.py
deleted file mode 100644
index 19ddfed..0000000
--- a/program/management/commands/importnotes.py
+++ /dev/null
@@ -1,62 +0,0 @@
-from django.contrib.auth.models import User
-from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
-from django.core.management.base import NoArgsCommand
-from django.utils.html import clean_html, strip_tags
-
-import MySQLdb
-
-from helsinki.program.models import Note, Show, TimeSlot
-
-USER = 'helsinki'
-PASSWD = 'helsinki'
-DB = 'helsinki'
-
-OWNER = User.objects.get(pk=1)
-
-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) AND n.titel != ''""")
-
- counter = 0
- for ntitel, datum, stitel, notiz in cursor.fetchall():
- ntitel = strip_tags(ntitel)
- stitel = strip_tags(stitel)
- notiz = clean_html(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)
-
- try:
- timeslot = TimeSlot.objects.get(programslot__show=show, start__year=year, start__month=month, start__day=day)
- except ObjectDoesNotExist:
- print 'no timeslot found for sendung "%s" and datum "%s"' % (stitel, datum)
- except MultipleObjectsReturned:
- print 'multiple timeslots found for sendung "%s" and datum "%s"' % (stitel, datum)
- else:
- note = Note(timeslot=timeslot, owner=OWNER, title=ntitel, content=notiz)
-
- try:
- note.save()
- except:
- print 'could not save note "%s" for show "%s" and datum "%s"' % (ntitel, stitel, datum)
- else:
- counter += 1
- except ObjectDoesNotExist:
- print 'show with name "%s" not found' % stitel
-
- cursor.close()
- connection.close()
-
- print '%i notes imported' % counter
diff --git a/program/management/commands/importprogramslots.py b/program/management/commands/importprogramslots.py
deleted file mode 100644
index 52aa73a..0000000
--- a/program/management/commands/importprogramslots.py
+++ /dev/null
@@ -1,96 +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 helsinki.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)
-
- 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:
- print 'show with name "%s" not found' % titel
- else:
- programslot = ProgramSlot(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, tstart=tstart,
- tend=tend, until=letzter_termin)
- try:
- programslot.save()
- counter += 1
- except:
- pass
- 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 = 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:
- print 'show with name "%s" not found' % titel
- else:
- programslot = ProgramSlot(rrule=rrule, byweekday=termin, show=show, dstart=erster_termin, tstart=tstart, tend=tend, until=letzter_termin, is_repetition=True)
- try:
- programslot.save()
- counter += 1
- except:
- pass
- 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
deleted file mode 100644
index b013dab..0000000
--- a/program/management/commands/importshows.py
+++ /dev/null
@@ -1,67 +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 clean_html, strip_tags
-
-import MySQLdb
-
-from helsinki.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 = clean_html(beschreibung)
-
- slug = slugify(titel)
-
- hosts = []
-
- for macher in macher.split(','):
- macher = macher.strip()
- try:
- host = Host.objects.get(name=macher)
- except MultipleObjectsReturned:
- print 'multiple hosts with name "%s" found' % macher
- except ObjectDoesNotExist:
- print 'host with name "%s" not found' % macher
- else:
- hosts.append(host)
-
- 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)
- try:
- show.save()
- counter += 1
- except:
- print 'sendung "%s" could not be imported' % titel
- else:
- for h in hosts:
- show.hosts.add(h)
- show.save()
-
- cursor.close()
- connection.close()
-
- print '%i shows imported' % counter