summaryrefslogtreecommitdiff
path: root/program/management/commands
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-04-27 16:13:37 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-04-27 16:13:37 (GMT)
commitf7f76cef63b6a274d3f5836b53508f343840d089 (patch)
treebeebe17a0c020e5a70a758027eab510da2898000 /program/management/commands
parentda67f298b845aef31403dafe73942207486dedf8 (diff)
parente1ea1fd45cd3aaa9b89e107fa22dfd95c7a34f77 (diff)
Merge branch 'master' into stable
Diffstat (limited to 'program/management/commands')
-rw-r--r--program/management/commands/export_showlog.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/program/management/commands/export_showlog.py b/program/management/commands/export_showlog.py
new file mode 100644
index 0000000..da78cd2
--- /dev/null
+++ b/program/management/commands/export_showlog.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+
+import codecs
+import sys
+from datetime import date, datetime, time, timedelta
+from django.core.management.base import BaseCommand, CommandError
+from program.models import TimeSlot
+
+
+class Command(BaseCommand):
+ help = 'export playlog for one year'
+ args = '<year>'
+
+ def handle(self, *args, **options):
+ UTF8Writer = codecs.getwriter('utf8')
+ sys.stdout = UTF8Writer(sys.stdout)
+
+ if len(args) == 1:
+ try:
+ year = int(args[0])
+ except ValueError:
+ raise CommandError("'%s' is not a valid year" % args[0])
+ else:
+ raise CommandError('you must provide the year')
+
+ print "# Radio Helsinki Sendungslog %d" % year
+
+ start = datetime.strptime('%d__01__01__00__00' % (year), '%Y__%m__%d__%H__%M')
+ end = datetime.strptime('%d__01__01__00__00' % (year+1), '%Y__%m__%d__%H__%M')
+
+ currentDate = None
+ for ts in TimeSlot.objects.filter(end__gt=start, start__lt=end).select_related('programslot').select_related('show'):
+ if currentDate == None or currentDate < ts.start.date():
+ if currentDate:
+ print "\n"
+ currentDate = ts.start.date()
+ print currentDate.strftime("## %a %d.%m.%Y:\n")
+
+ title = ts.show.name
+ if ts.programslot.is_repetition:
+ title += " (WH)"
+
+ print " * **%s - %s**: %s" % (ts.start.strftime("%H:%M:%S"), ts.end.strftime("%H:%M:%S"), title)
+