TVGuide-NL

 view release on metacpan or  search on metacpan

examples/tvgids.cgi  view on Meta::CPAN

	return @zenders_default;
}

# retrieve cookie
my @cookieval = cookie('zenders');
my $cookie = undef;
# and update expiry date
if (@cookieval)
{
    $cookie = cookie(
        -name       => 'zenders',
        -value      => \@cookieval,
        -expires    => '+100d',
        -domain     => $SERVER,
        -path       => $PATH,
    );
}

# == main =============================================================

# start by printing the http headers
# do this before any TVGuide things, so that error will be shown
# rather than just a 500 error
my $contenttype = 'application/xhtml+xml';
my $xmlheader   = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
unless (grep(m{^application/xhtml\+xml}, Accept))
{
	$contenttype = 'text/html';
	$xmlheader = '';
}

my %headers = (
	'-type'		=> $contenttype,
	'-charset'	=> 'utf-8',
	'-expires'  => '+30m',
	);
$headers{'-cookie'} = $cookie if ($cookie);

print header(%headers), $xmlheader;


# now initialize the TVGuide stuff
my $g = TVGuide::NL->new(debug=>0);
my @zenders = $g->station_code(GetStations($g,\@cookieval));
# update the info of all stations
$g->update_schedule(@zenders);


print <<"EOF";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl">
<head>
 <title>Wat is er op TV vandaag?</title>
 <link rel="alternate" type="text/xml" title="Films RSS Feed" href="films.rss" />
 <link rel="stylesheet" type="text/css" href="tvgids.css"/>
 <script type="text/javascript" src="tvgids.js"></script>
</head>
<body>
<h1>Wat is er op TV vandaag?</h1>
<p class="prefs"><a href="prefs.cgi">Instellingen</a></p>
EOF

my $i = 0;
for my $zender (@zenders)
{
	if ($zender eq 'Z0') 
	{
		print movietable($g, $i, @zenders);
	}
	else 
	{
		print progtable($g, $zender, $i);
	}
	$i++;
}

print <<"EOF";
</body>
</html>
EOF

exit(0);



sub progtable
{
	my $guide = shift;
	my $station = shift;
	my $num = shift || 0;

	my $result = '';
	
	my $clear = ''; 
	$clear = ' style="clear: left"' if ($num%3==0);
	
	$result .= '<div class="channel" id="'
		. $guide->station_abbr($station). "\" $clear>\n";
	$result .= " <h2>". encode_entities($guide->station_name($station),'<>&"') 
		. "</h2>\n";
	$result .= " <table class=\"channel\">\n";

	my $i = 0;
	foreach my $prog ( $guide->whats_on_today($station) )
	{
		my $odd = ($i++%2)?'odd':'even';
		$result .= "  <tr class=\"$odd\">";
		$result .= '<td class="time">';
		$result .= $prog->{'time'}; 
		$result .= '</td>';
		$result .= '<td class="program">';
		$result .= '<div class="title">';
		$result .= encode_entities($prog->{'title'},'<>&"');
		$result .= '</div>';
		$result .= '<div class="desc">';
		$result .= encode_entities($prog->{'desc'},'<>&"');
		$result .= '</div>';
		$result .= '</td></tr>';
		$result .= "\n";
	}



( run in 0.740 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )