#!/usr/bin/perl
#
#	$Id: news_mirror.pl,v 1.5 2003/04/10 18:38:43 kevin Exp $
#
#	Author: Kevin Walsh <kevin@cursor.biz>
#
#	Copyright (c) 2003 Cursor Software Limited.
#	All Rights Reserved.
#
#	Support script for the Plugins::BBCNews module.
#
#	Grabs the BBC news ticker data and saves it to a file if the
#	news has changed since the data was last checked.
#
#	This script requires the LWP::UserAgent module to be installed
#	and operational.
#
#	You should run this script periodically, as a cron job, so that
#	the news file is automatically kept up to date.
#
#	Note that this script is not required if you configure your
#	BBC News module to perform "live" lookups.  "Live" lookups are
#	inefficient and slow but users of certain crippled O/Ss have no
#	choice but to run that way.
#
#	----------------------------------------------------------------------
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
#	02111-1307 USA
#
use File::Spec::Functions qw(catfile catdir);
use LWP::UserAgent;
use strict;

#
#	if you need to use a proxy server then specify it here
#
# my $proxy = 'http://proxy.yourdomain.com:8080/';
#
my $proxy;

#
#	the $home directory must match the directory configured
#	into the Plugins::BBCNews module.  By default, that module
#	uses the SLIMP3 user's home directory, which is the same
#	directory where the ".slimp3.pref" file can be found
#
#	the example, below is /opt/slimp3
#
my $home = catdir('opt','slimp3');

#
#	you can add any number of web pages to mirror here
#
#	each line must consist of two columns: a filename and a URI
#
my %news = qw{
    bbcnews.txt		http://tickers.bbc.co.uk/tickerdata/story2.dat
};

#
#	end of configurable options
#

my $VERSION = substr(q$Revision: 1.5 $,10);

my $ua = new LWP::UserAgent;
$ua->agent("news_mirror/$VERSION");
$ua->proxy('http',$proxy) if $proxy;

while (my ($outfile,$uri) = each(%news)) {
    $outfile = catfile($home,$outfile) unless $outfile =~ m:^/:;
    $ua->mirror($uri,$outfile);
}

exit 0;

