Legend:
- Unmodified
- Added
- Removed
-
shepherd
r151 r158 3 3 # "Shepherd" 4 4 5 my $version = '0.2.2 6';5 my $version = '0.2.27'; 6 6 7 7 # A wrapper for various Aussie TV guide data grabbers … … 39 39 # 0.2.25 : use open-with-pipe rather than system() and look at 40 40 # return codes from called programmes 41 # 0.2.27 : Identify self in useragent when fetching shepherd files 41 42 42 43 BEGIN { *CORE::GLOBAL::die = \&my_die; } … … 44 45 use strict; 45 46 46 use LWP:: Simple;47 use LWP::UserAgent; 47 48 use Sort::Versions; 48 49 use Cwd; … … 1469 1470 &log("\nChecking for updates:\n\n"); 1470 1471 1471 my $data = fetch_ file("status");1472 my $data = fetch_shepherd_file("status"); 1472 1473 1473 1474 return unless ($data); … … 1564 1565 my $rfile = "$rdir/$proggy"; 1565 1566 1566 return unless (fetch_ file($rfile, $newfile));1567 return unless (fetch_shepherd_file($rfile, $newfile)); 1567 1568 1568 1569 # Fetch grabber config file 1569 1570 $rfile .= ".conf"; 1570 $config = fetch_ file($rfile);1571 $config = fetch_shepherd_file($rfile); 1571 1572 1572 1573 if (!$config) { … … 1618 1619 } 1619 1620 1620 sub fetch_ file1621 sub fetch_shepherd_file 1621 1622 { 1622 1623 my ($fn, $store) = @_; … … 1629 1630 foreach my $site (split(/,/,$sites)) 1630 1631 { 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); 1643 1634 } 1644 1635 return undef; … … 1851 1842 return ($? >> 8); 1852 1843 } 1844 } 1845 1846 sub 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; 1853 1880 } 1854 1881 … … 2146 2173 { 2147 2174 my @date = localtime; 2148 my $page = LWP::Simple::get(2175 my $page = fetch_file( 2149 2176 "http://au.tv.yahoo.com/results.html?rg=$region&dt=" . 2150 2177 ($date[5] + 1900) . "-$date[4]-$date[3]");
