#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::Simple;
use Archive::Any;
use POSIX 'strftime';

# This script pulls down a copy of todays TV-Anytime data and extracts it
# on to the file system in a new directory (names YYYYMMDD) every day.
# Version: 0.1 (20050903)
# License: GPL
# Author: Dean Wilson


# get the current date
my $today = strftime '%Y%m%d', localtime;

# the URL to get the data from :: config
my $data_url = "http://backstage.bbc.co.uk/feeds/tvradio/$today.tar.gz";

# the file and directory to store the data in :: config
my $saved_dir  = '/home/dwilson/notrealonlocalhost/chunks/';
my $saved_file = 'tvanytime.tar.gz';
my $saved_path = $saved_dir . $saved_file;

# try and get the file
if (is_success(getstore($data_url, $saved_path))) {

  # if we got it then extract it. This bit's slow
  my $archive = Archive::Any->new($saved_path);
  $archive->extract($saved_dir);

} else {
  die "Failed to get a file from '$data_url'"
}

