Plan Your TV Viewing





Plan Your TV Viewing

Yahoo! TV can help you plan what to watch and when to watch it.

Television is a big part of our lives; according to the Bureau of Labor Statistics, people spend about half of their leisure time watching TV. If you've ever started a long channel-surfing binge, you know that you can feel you've wasted that leisure time by the time you're done. Even though we now have hundreds of channels to choose from, it can still be hard to find something to watch.

It shouldn't be a surprise that TV Guide is one of the top-selling magazines in the country. It takes a bit of energy to really find what you're interested in, and Yahoo! TV can help you plan so you won't be wasting your time scanning. To get to Yahoo! TV, browse to http://tv.yahoo.com or type tv! into any Yahoo! Search form. Here's a look at what you'll find at the site:


TV Listings

Enter your Zip Code at http://tv.yahoo.com/grid, and you'll find what shows are on each of your channels, whether you have cable, satellite, or rabbit ears. You can view shows by time and date, limit listings to certain categories, or create a custom lineup of your favorite channels.


Picks from Yahoo! Editors

Yahoo! TV editors offer their take on the best bets for viewing, as well as brief synopses of the shows at http://tv.yahoo.com/picks. You can take a look at editors' choices for that day or move back or forward a few days.


TV News and Gossip

Find out what's happening in the television industry and what TV celebrities are up to. You can even read about celebrities at their worst from several different supermarket tabloids at http://tv.yahoo.com/entgossip.


Nielsen Ratings

Find out which shows had the highest numbers of viewers for the week, as calculated by Nielsen. You'll find the Top 20 at http://tv.yahoo.com/nielsen.


TV Show Database

You can look up television shows to read a brief synopsis, see photographs of the actors, and review descriptions of upcoming episodes. Browse to http://tv.yahoo.com/db and search alphabetically or by genre. The database contains listings for shows from the late 1980s through today.


Soap Opera Synopses

Miss an episode of your favorite soap? Browse to http://tv.yahoo.com/soaps and you'll be caught up on who was sleeping with whom and whether their amnesia has worn off.


Message Boards

Discuss shows with other Yahoo! users at the Yahoo! Message Boards by browsing to http://messages.yahoo.com and clicking the TV link under Hot Topics on the left side of the page. You can also find many Yahoo! Groups devoted to specific programs or general TV discussion at http://tv.dir.groups.yahoo.com.

Personalize Your Listings

One of the most useful features is personalized TV listings. To personalize your listings, bring up the Yahoo! TV site (http://tv.yahoo.com) and sign in with your Yahoo! ID [Hack #3] by clicking the Sign In link on the right side of the page. If you don't have a Yahoo! ID, you can still temporarily personalize the TV listings by clicking the My Listings link, but keep in mind that your listings won't be available across different browsers and computers you use without signing in, and you won't be able to save your favorite channels.

You'll need to enter your Zip Code, which will narrow your choices down to cable, broadcast, and satellite listings for your area. Choose your provider from those listed and click Go!. You should see listings for all of the channels you receive. Click the Create Personalized Listings link at the top of the page to create a list of your favorite channels. Highlight a channel on the left and click the Add button; the channel will appear in the Your Choices box on the right.

You can also set your display preferences and a preferred start time. You can either display the first 15, 30, or 45 channels, or just display your favorite channels. You can also set the start time as 7:00 or 8:00 p.m. to display prime-time shows as your default display. Setting these preferences lets Yahoo! know which listings to show in My Yahoo!.

Click Finished and you should see a list of what's currently playing on your favorite channels, as shown in Figure.

A schedule of Favorite Channels at Yahoo! TV


Once your favorites are set, you can also keep tabs on the schedule at My Yahoo! (http://my.yahoo.com). Figure shows listings on My Yahoo!, with favorite channels set to begin at 8:00 p.m.

If you'd rather not visit a Yahoo! web site to view your schedule, Yahoo! doesn't offer any options for you yet. But with some Perl scripting, you can create your own options.

Email Your Listings

If you're more of an email person than a web person and prefer to read information in your inbox instead of a browser, some quick scripting can take care of that for you. This hack relies on screen scraping to gather data, and the usual caveats apply, because any change to the HTML that Yahoo! uses to display TV listings could break this script. Be aware that you might need to tweak this code from time to time.

The TV Listings module at My Yahoo!


To run this hack, you'll need your Yahoo! TV personalized listings URL and a computer that can run Perl scripts. If you haven't already personalized your listings, you'll need to back up and set your location and TV provider. Once it's set up, browse to the Yahoo! TV front page (http://tv.yahoo.com) and click on the My Personalized Listings link at the top of the page. Note the URL in your browser's address bar. It should look something like this:

	http://tv.yahoo.com/grid?lineup=us_OR36403&zip=97333

You'll need to add this URL to the code so the script knows where to get your listings.

The code.

This code uses three modules that you might need to install. LWP::Simple handles fetching the TV listings and Net::SMTP sends the email the script builds. As you'd expect, Date::Format handles some simple date formatting.

This script doesn't actually log in to your Yahoo! account, so you won't see your favorite channels in the email. Instead, you'll see all of the channels from your cable, satellite, or broadcast listings.


Save the following code to a file called whats_on.pl and include your personalized listings URL, your mail server, and your email address. You can also change the value of $starthour to get listings for another time of day. It's set to 20, which is 8:00 p.m. on a 24-hour clock, and this will give you listings for prime-time shows.


	#!/usr/bin/perl
	# whats_on.pl
	# A script to download a Yahoo! TV schedule
	# and send it via email
	# Usage: whats_on.pl

	use strict;
	use LWP::Simple;
	use Net::SMTP;
	use Date::Format;

	# Set your start time in 24-hour hh format
	my $starthour = 20;

	# Set the Yahoo! TV URL
	my $url = "insert your personalized listings URL";
	   $url .= "&starthour=$starthour&prt=1";

	# Set email info
	my $subject = "On TV Tonight";
	my $smtp_server = "insert your mail server";
	my $from_email = 'insert your email address';
	my $to_email = 'insert your email address';

	# Grab the Yahoo! TV listings page and
	my $body = get($url);
	my ($lastchannel,$out);

	# Build the email by looping through the HTML
	# and picking out the important stuff
	my $regex = '<td.*?>.*?<a href=".*?chname=(.*?)&.*?progutn=(.*?)&';
	   $regex .= '.*?">(.*?)</a>.*?</td>';
	my $out = "On TV tonight--";
	while ($body =~ m!$regex!gis) {
		my $channel = $1;
		my $channel_f = $1;
		my $time = $2;
		my $title = $3;
		if ($lastchannel ne $channel) {
			$channel_f =~ s!\+(\d{1,2})! \($1\)!;
			$out .= "\n\n$channel_f\n\n";
		}
		my $airtime = time2str("%l:%M", $time);
		$out .= " $airtime $title\n";
		$lastchannel = $channel;
	}

	# Send the schedule via email
	my $dtm = time2str("%m%d%Y%T", time);
	my $smtp = Net::SMTP->new($smtp_server);
	$smtp->hello($smtp_server);
	$smtp->mail($from_email);
	$smtp->to($to_email);
	$smtp->data();
	$smtp->datasend("From: $from_email\n");

	$smtp->datasend("To: $to_email\n");
	$smtp->datasend("Subject: $subject\n");
	$smtp->datasend("Message-Id: tv.yahoo.com-sched-$dtm\@$smtp_server\n");
	$smtp->datasend('Content-Type: text/plain;');
	$smtp->datasend("\n\n");
	$smtp->datasend($out);
	$smtp->dataend();
	$smtp->quit;

	# Close output file
	close(FILE);

Notice that $url holds your personalized listings URL and adds a couple of querystring variables and values, including starthour and prt=1, which sets the page to the Printable View on Yahoo!, which is easier to scrape.

The $regex variable holds the patterns the script uses to find the relevant bits of information in the HTML, and you might need to adjust this regular expression if Yahoo! modifies their HTML.

Running the hack.

To run this script once, you can just call it from the command line, like this:

	perl whats_on.pl

To really take advantage of the script, set it to run daily with the Windows Scheduler or by adding a cron job on Unix-based machines. Once set, you'll receive daily emails like the one shown in Figure, with the prime-time TV schedule listed by channel.

TV listings email


The text listing in the email is simple and includes only the channel, time, and program name. If you like to read information in your inbox, though, it's a no-frills way to find out what's going to be on TV.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows