Changeset 158 for shepherd

Show
Ignore:
Timestamp:
10/26/06 17:59:02 (7 years ago)
Author:
max
Message:

Identify self in useragent string when fetching shepherd files.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • shepherd

    r151 r158  
    33# "Shepherd" 
    44 
    5 my $version = '0.2.26'; 
     5my $version = '0.2.27'; 
    66 
    77# A wrapper for various Aussie TV guide data grabbers 
     
    3939# 0.2.25  : use open-with-pipe rather than system() and look at 
    4040#           return codes from called programmes 
     41# 0.2.27  : Identify self in useragent when fetching shepherd files 
    4142 
    4243BEGIN { *CORE::GLOBAL::die = \&my_die; } 
     
    4445use strict; 
    4546 
    46 use LWP::Simple; 
     47use LWP::UserAgent; 
    4748use Sort::Versions; 
    4849use Cwd; 
     
    14691470    &log("\nChecking for updates:\n\n"); 
    14701471 
    1471     my $data = fetch_file("status"); 
     1472    my $data = fetch_shepherd_file("status"); 
    14721473 
    14731474    return unless ($data); 
     
    15641565    my $rfile = "$rdir/$proggy"; 
    15651566 
    1566     return unless (fetch_file($rfile, $newfile)); 
     1567    return unless (fetch_shepherd_file($rfile, $newfile)); 
    15671568 
    15681569    # Fetch grabber config file 
    15691570    $rfile .= ".conf"; 
    1570     $config = fetch_file($rfile); 
     1571    $config = fetch_shepherd_file($rfile); 
    15711572 
    15721573    if (!$config) { 
     
    16181619} 
    16191620 
    1620 sub fetch_file 
     1621sub fetch_shepherd_file 
    16211622{ 
    16221623    my ($fn, $store) = @_; 
     
    16291630    foreach my $site (split(/,/,$sites))  
    16301631    { 
    1631         &log("Fetching $site/$fn.\n"); 
    1632         if ($store) 
    1633         { 
    1634             $ret = LWP::Simple::getstore("$site/$fn", $store); 
    1635             return 1 if (is_success($ret)); 
    1636         } 
    1637         else 
    1638         { 
    1639             $ret = LWP::Simple::get("$site/$fn"); 
    1640             return $ret if ($ret); 
    1641         } 
    1642         &log("Failed to retrieve $site/$fn.\n"); 
     1632        $ret = fetch_file("$site/$fn", $store, 1); 
     1633        return $ret if ($ret); 
    16431634    } 
    16441635    return undef; 
     
    18511842        return ($? >> 8); 
    18521843    } 
     1844} 
     1845 
     1846sub fetch_file 
     1847{ 
     1848    my ($url, $store, $id_self) = @_; 
     1849 
     1850    &log("Fetching $url.\n"); 
     1851     
     1852    my $ua = LWP::UserAgent->new(); 
     1853    if ($id_self) 
     1854    { 
     1855        $ua->agent(ucfirst("$progname/$version")); 
     1856    } 
     1857    else 
     1858    { 
     1859        $ua->agent('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322') 
     1860    } 
     1861 
     1862    my $response = $ua->get($url); 
     1863    if ($response->is_success()) 
     1864    { 
     1865        if ($store) 
     1866        { 
     1867            open (FILE, ">$store")  
     1868                or (&log("ERROR: Unable to open $store for writing.\n") and return undef); 
     1869            print FILE $response->content(); 
     1870            close FILE; 
     1871            return 1; 
     1872        } 
     1873        else  
     1874        { 
     1875            return $response->content(); 
     1876        }  
     1877    } 
     1878    &log("Failed to retrieve $url!\n" . $response->status_line() . "\n"); 
     1879    return undef; 
    18531880} 
    18541881 
     
    21462173{ 
    21472174    my @date = localtime; 
    2148     my $page = LWP::Simple::get( 
     2175    my $page = fetch_file( 
    21492176        "http://au.tv.yahoo.com/results.html?rg=$region&dt=" . 
    21502177        ($date[5] + 1900) . "-$date[4]-$date[3]");