xmltv

 view release on metacpan or  search on metacpan

grab/na_dd/tv_grab_na_dd.IN  view on Meta::CPAN

# open dd data file (temp, or created)
#
if ($opt_reprocess)
{
    die "$opt_dd_data file not found\n" unless -e $opt_dd_data;
    $dd_data_name = $opt_dd_data;
    $dd_data      = new IO::File("<$dd_data_name");
    $dd_data_size= -s $dd_data;
}
else
{
#
# get DD data
#
    #
    # open file to store DD XML
    #
    if ($opt_dd_data)
    {
        $dd_data_name = $opt_dd_data;
        $dd_data      = new IO::File("+>$dd_data_name");
    }
    else
    {
        ($dd_data,$dd_data_name) = tempfile('tv_grab_na_dd_XXXX',
                                             DIR    => File::Spec->tmpdir(),
                                             SUFFIX => '.tmp',
                                             UNLINK=>($DEBUG ? 0 : 1));
    }

#
# Prompt for password (if needed)
#
    $dd_pass=~s/^\s//g;
    unless (length($dd_pass))
    {
        require Term::ReadKey;
        $| = 1;
        print STDERR "Password for $dd_user: ";
        Term::ReadKey::ReadMode('noecho');
        chomp($dd_pass = <STDIN>);
        Term::ReadKey::ReadMode('restore');
        print STDERR "\n";
    }

#
# Fetch data
# 
    print STDERR "Fetching from DataDirect\n";
    print STDERR "    dd_data is in $dd_data_name\n" if $DEBUG || $opt_dd_data;   

    sub SOAP::Transport::HTTP::Client::get_basic_credentials
    {
       return "$dd_user" => "$dd_pass";
    }

    my $dd_service='http://docs.tms.tribune.com/tech/tmsdatadirect/zap2it/xtvd.wsdl';
    $dd_service='http://docs.tms.tribune.com/tech/tmsdatadirect/zap2it/beta/xtvd.wsdl' if $opt_beta_data;

    my $proxy='http://localhost/';
    if (exists $ENV{HTTP_PROXY})
    {
        $proxy=$ENV{HTTP_PROXY};
    }

    my $time=time();
    my $soap= SOAP::Lite
            -> service($dd_service)
            -> outputxml('true')
#           -> on_debug(1)
            -> on_fault( sub {
                             	my($soap,$res)=@_;
                              	die "SOAP call failed: "
                             	    .(ref $res ? $res->faultstring
                              	               : $soap->transport->status)
                              	    ."\n";
                             })
            -> proxy($proxy, options => {compress_threshold => 10000,
                                         timeout            => 420});
    $dd_data->print($soap->download("<startTime>$dd_start</startTime><endTime>$dd_stop</endTime>"));
    $dd_data->flush;
    $dd_data_size= -s $dd_data;
    die 'got empty result from SOAP call' if $dd_data_size == 0;
    $time = int(time() - $time);
    printf STDERR "    Fetched %d k/bytes in %d seconds\n",$dd_data_size/1024,$time;
} # get data

#
# quit if --download-only
#
exit(0) if $opt_down_only;

#
# load supporting details
#
my $twig=XML::Twig->new(   
         twig_roots    => { HTML => 1, message => 1, xtvd => 1 },
         ignore_elts   => { schedules => 1 },
		 twig_handlers => 
		      {
		         HTML     => sub {
                                  die "\n*** FETCH ERROR***\n".$_->first_child_text;
                		         },
                 xtvd  => sub {
                                  $dd_schema=$_->att('schemaVersion');
				  die "did not see schemaVersion attribute in <xtvd>"
				    if not defined $dd_schema;
                                  $_->twig->purge;
                                  return 0;
                                 },
                 message  => sub {
                                  push @messages, $_->first_child_text;
                                  $_->twig->purge;
                                  return 0;
                                 },

		         stations => sub { $_->twig->purge;  return 0;},
		         station  => sub {
                                  my $hash=$_->simplify;
                                  $station{$_->att('id')}=$hash;
                                  $_->twig->purge;
                                  return 0;
                		         },



( run in 3.771 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )