Inspired by some of the appalling TV listings websites, I decided I'd roll my own page with this script. It takes an XMLTV format input file (which can contain multiple channels) and generates a webpage with the times approximately aligned and the descriptions on mouseover. I have a seperate script which downloads the xml data from http://www.bleb.org/tv/data/listings/ you can see an example of the output at http://patter.mine.nu/~steve/newTV/ but please be gentle, I don't have much bandwidth.
#!/usr/bin/perl use strict; use XML::Simple; use Data::Dumper; use CGI qw/:all/; print header('text/html'); print <<__STYLE__ <style type="text/css"> td { vertical-align: top; } </style> __STYLE__ ; my $tv = XMLin('raw.xml'); # channel names & global channel info - array of hashes # can xref with programs by key: blebid my $chan_names = $tv->{xmltvid}; # generate cross-referencing hash my $chan_names = $tv->{xmltvid}; # generate cross-referencing hash my %xmltvid; foreach my $chan (@$chan_names) { $xmltvid{$chan->{content}} = $chan->{blebid}; } # programs on BBC 1 - ref to array of hashes [example] # my $channel = $tv->{channel}->{$xmltvid{'BBC 1'}}->{programme}; # &all_shows($channel, 'BBC 1'); print "<table border>\n"; &all_shows(); print "</table>\n"; sub all_shows { # my ($chanref, $channame) = @_; print "<tr>\n"; foreach my $chan (keys %xmltvid) { print " <th>$chan</th>\n"; } foreach my $hour (0 .. 23) { print "</tr>\n<tr>\n"; &this_hour($tv, $hour); print "</tr>\n<tr>\n"; &this_hour($tv, $hour); print "</tr><tr>\n"; } } sub this_hour { my ($tvref, $hour) = @_; # print '<pre>', Dumper $tvref, '</pre>'; foreach my $chan (keys %xmltvid) { # my $chan = 'BBC 1'; my $chanref = $tvref->{channel}->{$xmltvid{$chan}}->{programm +e}; print " <td>"; # print "<pre>", Dumper $chanref, "</pre>\n"; my $i = 0; foreach my $prog (@$chanref) { if (substr($prog->{start}, 0, 2) == $hour) { print '<table><tr><td>', $prog->{start}, '-', $prog->{end}, '</td>', "<td><div title='$prog->{subtitle} $prog->{desc}'>$pro +g->{title}", "</div></td></tr></table>"; } } } }
The other script which fetches the XMLTV data is a crufty little shell script which could probably be perlified with LWP::Simple and Archive::Zip, but its simpler this way :)
#!/bin/sh wget 'http://www.bleb.org/tv/data/listings?format=XMLTV&file=zip&chann +els=bbc1,bbc2,bbc3,bbc4,bbc7,itv1,ch4,five,abc1,bbc_6music,bbc_radio2 +,bbc_radio4,e4,itv2,itv3,uk_history&days=0' -O ~/public_html/newTV/bl +eb.zip --quiet unzip -qq -o -d ~/public_html/newTV ~/public_html/newTV/bleb.zip
just another cpan module author

Edit: g0n - linkified http links


In reply to Displaying TV Listings (and no screen-scraping ) by spatterson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.