sub-bass sessions, hehe
[radio.haze.st.git] / index.cgi
1 #!/usr/bin/perl -w
2
3 $template_file = "/home/ivan/radio.haze.st/template.html";
4
5 use CGI;
6 use HTML::Table;
7 use Text::Template;
8
9 %type2color = (
10   'upcoming'    => '999966',
11   'live'        => 'ffffcc',
12   'rebroadcast' => 'ffcc99',
13 );
14
15 %shows = (
16   'high_jinx' => {
17     'name'  => 'High Jinx',
18     'day'   => 'sunday',
19     'start' => '19',
20     'len'   => '3',
21     'type'  => 'upcoming',
22     'startdate' => 'May 6th',
23   },
24   'high_jinx_rebroadcast' => {
25     'name'  => 'High Jinx',
26     'day'   => 'monday',
27     'start' => '13',
28     'len'   => '3',
29     'type'  => 'upcoming',
30     'startdate' => 'May 7th',
31   },
32   'dub_monday' => {
33     'name'  => 'Dub Monday',
34     'day'   => 'monday',
35     'start' => '19.5',
36     'len'   => '2',
37     'url'   => 'http://www.voyager.org/sets',
38     'type'  => 'live',
39   },
40   'dub_monday_rebroadcast' => {
41     'name'  => 'Dub Monday',
42     'day'   => 'tuesday',
43     'start' => '13',
44     'len'   => '2',
45     'url'   => 'http://www.voyager.org/sets',
46     'type'  => 'rebroadcast',
47   },
48   'organized_chaos' => {
49     #'name'  => 'Organized<BR>Chaos',
50     'name'  => 'Organized Chaos',
51     'day'   => 'wednesday',
52     'start' => '20',
53     'len'   => '3',
54     'url'   => 'http://www.angelfire.com/rant/burf/oc.html',
55     'type'  => 'live',
56   },
57   'organized_chaos_rebroadcast' => {
58     #'name'  => 'Organized<BR>Chaos',
59     'name'  => 'Organized Chaos',
60     'day'   => 'thursday',
61     'start' => '13',
62     'len'   => '3',
63     'url'   => 'http://www.angelfire.com/rant/burf/oc.html',
64     'type'  => 'rebroadcast',
65   },
66   'echo_communication_system' => {
67     #'name'  => 'Echo<BR>Communication<BR>System',
68     #'name'  => 'Echo Communication System',
69     'name'  => 'Echo Communication System',
70     'day'   => 'thursday',
71     'start' => '20',
72     'len'   => '3',
73     'url'   => 'http://www.theoverworld.com/echo/',
74     'type'  => 'live',
75   },
76   'echo_communication_system__rebroadcast' => {
77     #'name'  => 'Echo<BR>Communication<BR>System',
78     #'name'  => 'Echo Communication System',
79     'name'  => 'Echo Communication System',
80     'day'   => 'friday',
81     'start' => '13',
82     'len'   => '3',
83     'url'   => 'http://www.theoverworld.com/echo/',
84     'type'  => 'rebroadcast',
85   },
86   'sub_bass_sessions' => {
87     'name'  => 'Sub-Bass Sessions',
88     'day'   => 'tuesday',
89     'start' => '20',
90     'len'   => '2',
91     'type'  => 'live',
92   },
93   'sub_bass_sessions_rebroadcast' => {
94     'name'  => 'Sub-Bass Sessions',
95     'day'   => 'wednesday',
96     'start' => '13',
97     'len'   => '2',
98     'type'  => 'rebroadcast',
99   },
100 );
101
102 @times = qw( midnight 1am 2am 3am 4am 5am 6am 7am 8am 9am 10am 11am noon 1pm
103              2pm 3pm 4pm 5pm 6pm 7pm 8pm 9pm 10pm 11pm );
104 $increment = 0.5;
105 $showstart = 12;
106
107 $cgi = new CGI;
108 if ( defined($cgi->param('showstart'))
109      && $cgi->param('showstart') =~ /^(\d+)$/ ) {
110   die unless $1 < 24;
111   $showstart = $1;
112 }
113
114 @showtimes = @times[$showstart..23];
115
116 $template = new Text::Template ( TYPE => 'FILE', SOURCE => $template_file )
117   or die "Can't create template for $template_file: $Text::Template::ERROR";
118
119 my $text = $template->fill_in()
120   or die "Can't fill in template for $template_file: $Text::Template::ERROR";
121
122 print $cgi->header, $text;
123
124 # subroutines for the template
125
126 sub table {
127
128   my $rows = 1 + scalar(@showtimes)*(1/$increment);
129   #$rows += 10;
130   my $table = new HTML::Table($rows+20,8+2);
131 #  $table->setBorder(0);
132   $table->setCellSpacing('0');
133   $table->setCellPadding('1');
134
135   my $daycol=2;
136   foreach my $day ( map "${_}day", qw( Sun Mon Tues Wednes Thurs Fri Satur ) ) {
137     $table->setCell(1, $daycol, "<B>${day}</B>" );
138     $table->setCellAlign(1, $daycol, 'CENTER');
139
140     my @dayshows =
141       sort { $shows{$a}{'start'} <=> $shows{$b}{'start'} }
142       grep { lc($shows{$_}{day}) eq lc($day) } keys %shows;
143     my $pshowrow = 2;
144     foreach my $show ( @dayshows ) {
145
146       my $text = "<B>$shows{$show}{name}</B>";
147       $text = qq(<A HREF="$shows{$show}{url}">$text</A>)
148         if exists $shows{$show}{url};
149       if ( $shows{$show}{type} eq 'upcoming' ) {
150         $text .= qq(<BR><FONT SIZE="-1">starts $shows{$show}{startdate}</FONT>);
151         #$text .= '<BR><FONT SIZE="-1">starts&nbsp;May&nbsp;Xth</FONT>';
152       }
153       if ( $shows{$show}{type} eq 'live' ) {
154         $text .= "<BR><B>LIVE</B> ";
155       }
156       if ( $shows{$show}{type} eq 'rebroadcast' ) {
157         #$text .= "<BR><B>rebroadcast</B> ";
158         $text .= qq(<BR><FONT SIZE="-1">rebroadcast</FONT> );
159       }
160       if ( $shows{$show}{type} =~ /^(live|rebroadcast)$/ ) {
161         my $start = $shows{$show}{start};
162         my $stext = $times[ $start ];
163         $stext =~ s/([0-9])([ap]m)/$1:30$2/ if $start != int($start);
164         my $end = $shows{$show}{start} + $shows{$show}{len};
165         my $etext = $times[$end];
166         $etext =~ s/([0-9])([ap]m)/$1:30$2/ if $end != int($end);
167         #$text .= "<B>$stext-$etext</B>";
168         $text .= qq(<FONT SIZE="-1">$stext-$etext</FONT>);
169       }
170
171       my $showrow = 2 + (1/$increment) * ( $shows{$show}{start} - $showstart);
172
173       if ( $pshowrow < $showrow ) {
174         #$table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>'. "($showrow/$pshowrow) ".($showrow-$pshowrow));
175         $table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>');
176         $table->setCellAlign($pshowrow, $daycol, 'CENTER');
177         $table->setCellRowSpan( $pshowrow, $daycol, $showrow-$pshowrow );
178         #$table->setCellRowSpan( $pshowrow, $daycol, 1 );
179         $table->setCellBGColor( $pshowrow, $daycol, '89201b' );
180       }
181       $table->setCell($showrow, $daycol, $text );
182       $table->setCellAlign($showrow, $daycol, 'CENTER');
183       $table->setCellBGColor($showrow, $daycol,
184                              $type2color{$shows{$show}{type}});
185       my $span = $shows{$show}{len} * (1/$increment);
186       $table->setCellRowSpan($showrow, $daycol, $span );
187
188       $pshowrow=$showrow+$span;
189     }
190
191     if ( $pshowrow < $rows+1 ) {
192       #$table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>'. "($rows+1/$pshowrow) ".($rows+1-$pshowrow));
193       $table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>');
194       $table->setCellAlign($pshowrow, $daycol, 'CENTER');
195       $table->setCellRowSpan( $pshowrow, $daycol, $rows+1-$pshowrow );
196       #$table->setCellRowSpan( $pshowrow, $daycol, 2 );
197       $table->setCellBGColor( $pshowrow, $daycol, '89201b' );
198     }
199
200     $daycol++;
201   }
202
203   my $timerow = 2;
204   foreach my $time ( @showtimes ) {
205     my $text = $time;
206     $text = qq(<FONT SIZE="-1">$text</FONT>) if length($text) > 4;
207     $table->setCell( $timerow, 1, "<B>$text</B>" );
208     $table->setCellAlign( $timerow, 1, 'CENTER' );
209     $table->setCellRowSpan( $timerow, 1, 1/$increment );
210     #$table->setCell( $timerow+1, 1, "<B>$text:30</B>" );
211 #    $table->setCell( $timerow+1, 1, "&nbsp;" );
212 #    $table->setCellAlign( $timerow+1, 1, 'CENTER' );
213     $timerow += 1/$increment;
214   }
215
216   local $^W=0;
217   my $html = $table->getTable;
218   $html =~ s/<! spanned cell\)>//g;
219   return $html;
220 }
221
222