Changeset 826

Show
Ignore:
Timestamp:
07/01/07 05:15:10 (6 years ago)
Author:
paul
Message:

abc_website: remove some unused 'use' statements, set defaults for Shepherd::Common, minor message changes, use Shepherd::Common::print_stats, wait an extra 2 days before clearing cache, simplify what days to grab because wasn't helpful, removed the insertion of fake 'Station Close' and replaced with a cached version of the true 'Station Close' (wont work the first day because nothing yet cached), only return programmes for requested days, use Shepherd::Common::log for all logs except printf, still has gaps for abc2 on days beyond weekly 'Station Close' data

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • grabbers/abc_website

    r810 r826  
    2323 
    2424my $progname = "abc_website"; 
    25 my $version = "3.08"; 
    26  
    27 use LWP::UserAgent; 
     25my $version = "3.09"; 
     26 
    2827use XMLTV; 
    2928use POSIX qw(strftime mktime); 
    3029use Getopt::Long; 
    3130use HTML::TreeBuilder; 
    32 use Data::Dumper; 
    3331use Storable; 
    3432use Shepherd::Common; 
     
    5351my $data_cache; 
    5452my $override_settings = { }; 
    55 my $station_close_data; 
    5653my $writer; 
    5754$| = 1; 
     
    121118die "no channel file specified, see --help for instructions\n", if ($opt_channels_file eq ""); 
    122119 
     120# set defaults 
     121&Shepherd::Common::set_default("debug", (defined $debug ? ($debug * 2) : 0)); 
     122&Shepherd::Common::set_defaults(stats => \%stats, referer => "last"); 
     123 
    123124# 
    124125# go go go! 
    125126# 
    126127 
    127 my $starttime = time; 
    128128&read_cache if ($opt_no_cache == 0); 
    129129 
     
    135135die "nothing to do; neither ABC nor ABC2 in channels lineup!\n" if ((!defined $channels->{ABC}) && (!defined $channels->{ABC2})); 
    136136 
    137 &log(sprintf "going to %s%s %s%d%s days%s of data for ABC(%s), ABC2(%s) into %s (%s)", 
     137&log(sprintf "Going to %s%s %s%d%s days%s of data for ABC(%s), ABC2(%s) into %s (%s)", 
    138138        ($opt_gaps_file ne "" ? "micro-gap " : ""), 
    139139        ($opt_cheap ? "verify (cache-validate)" : "grab"), 
     
    177177$writer->end; 
    178178 
    179 &print_stats; 
     179&Shepherd::Common::print_stats($progname, $version, $script_start_time, %stats); 
    180180exit(0); 
    181181 
     
    267267        for my $cache_key (keys %{$data_cache}) { 
    268268                my ($starttime, @rest) = split(/,/,$cache_key); 
    269                 if ($starttime < (time-86400)) { 
     269                if ($starttime < ($script_start_time - (2*24*60*60))) { 
    270270                        delete $data_cache->{$cache_key}; 
    271271                        $stats{removed_items_from_cache}++; 
     
    291291        my @gap_s, my @gap_e; 
    292292 
    293         my $daynum = $opt_offset; 
    294         $opt_days = 28 if (($opt_do_extra_days) && ($opt_gaps_file eq "") && ($opt_offset == 0) && ($opt_days == 7)); 
    295         my $days_left = $opt_days - $opt_offset; 
    296  
    297         my @timeattr = localtime($starttime); # 0=sec,1=min,2=hour,3=day,4=month,5=year,6=wday,7=yday,8=isdst 
    298         # if now before 4:30am we need the previous day due to the guide starting at 4:30am 
    299         if (($daynum == 0 and ($timeattr[2] < 4 or ($timeattr[2] == 4 and $timeattr[1] < 30))) or $daynum < 0) { 
    300                 $daynum = -1; 
    301                 $days_left = $opt_days + 1; 
    302         } elsif ($daynum > 0) { 
    303                 $daynum--; 
    304                 $days_left++; 
    305         } 
     293        $opt_days = 28 if ($opt_do_extra_days); 
     294 
     295        # guide pages start at 4:30am so grab day before 
     296        my $daynum = $opt_offset - 1; 
     297        my $days_left = $opt_days - $opt_offset + 1; 
     298 
     299        my @timeattr = localtime($script_start_time); # 0=sec,1=min,2=hour,3=day,4=month,5=year,6=wday,7=yday,8=isdst 
    306300        $timeattr[0] = 0; # zero seconds 
    307301        $timeattr[3] += $daynum - 1; # day 
     
    311305                $daynum++; 
    312306 
     307                # guide page starts at 4:30am 
    313308                $timeattr[1] = 30; # minutes 
    314309                $timeattr[2] = 4; # hours 4:30am 
     
    339334                &log((sprintf "Fetching %s summary data: day %d of %d", 
    340335                        $xmlid, $daynum, $opt_days )); 
    341                 my $data = Shepherd::Common::get_url(url => $url, retries => ($tries-1), debug => $debug * 2); 
     336                my $data = Shepherd::Common::get_url(url => $url, retries => ($tries-1)); 
    342337                my $tree; 
    343338                $tree = HTML::TreeBuilder->new_from_content($data) if ($data); 
     
    394389                                                                                $daynum,$tree_row->as_text(),POSIX::strftime("%Y%m%d%H%M", localtime($found_time)), 
    395390                                                                                $programme,$progurl if ($debug && $debug > 1); 
    396                                                                         # If it's day 1 and the first programme found  
    397                                                                         # starts later than now, insert a Station Close  
    398                                                                         # from now until then. Without this, we have a 
    399                                                                         # hole if run during a Station Close period  
    400                                                                         # (eg midnight - 6am). 
    401                                                                         if (!$seen_programmes and $daynum == 1 and $found_time > $script_start_time) 
    402                                                                         { 
    403                                                                             &log("Inserting initial Station Close"); 
    404                                                                             $unprocessed_progname[$unprocessed_programmes] = "Station Close"; 
    405                                                                             $unprocessed_starttime[$unprocessed_programmes] = $script_start_time; 
    406                                                                             $unprocessed_day[$unprocessed_programmes] = $daynum; 
    407                                                                             $unprocessed_url[$unprocessed_programmes] = ""; 
    408                                                                             $unprocessed_programmes++; 
    409                                                                         } 
    410391 
    411392                                                                        $unprocessed_progname[$unprocessed_programmes] = $programme; 
     
    431412                        $stats{abc_daily_pages}++; 
    432413 
    433                         if ((defined $station_close_data) && (defined $station_close_data->{$xmlid}) && 
    434                             (defined $station_close_data->{$xmlid}->[$daynum])) { 
     414                        my $cache_key = sprintf "%d,%d,%s,%s", $currtime, 0, $xmlid, "Station Close"; 
     415                        if (defined $data_cache->{$cache_key}) { 
    435416                                # get station-close time from the previously-fetched "weekly programme guide" 
    436                                 &log("inserting Station Close"); 
     417                                &log(" Inserting 'Station Close'"); 
    437418 
    438419                                $unprocessed_progname[$unprocessed_programmes] = "Station Close"; 
    439                                 $unprocessed_starttime[$unprocessed_programmes] = $station_close_data->{$xmlid}->[$daynum]; 
     420                                $unprocessed_starttime[$unprocessed_programmes] = $data_cache->{$cache_key}; 
    440421                                $unprocessed_day[$unprocessed_programmes] = $daynum; 
    441422                                $unprocessed_url[$unprocessed_programmes] = ""; 
     
    453434 
    454435        # have 'n' days of this channel unprocessed - process it! 
    455         &log((sprintf "have summary data for %s, now fetching detail pages for up to %d programmes..",$chan_id,$unprocessed_programmes-2)); 
     436        &log((sprintf "Have summary data for %s, now fetching detail pages for up to %d programmes..",$chan_id,$unprocessed_programmes-2)); 
     437 
     438        # only return programmes for requested days 
     439        @timeattr = localtime($script_start_time); # 0=sec,1=min,2=hour,3=day,4=month,5=year,6=wday,7=yday,8=isdst 
     440        $timeattr[0] = 0; # zero seconds 
     441        $timeattr[1] = 0; # zero mintues 
     442        $timeattr[2] = 0; # zero hours 
     443        $timeattr[3] += $opt_offset; # day 
     444        my $start_day = mktime(@timeattr); 
     445        $timeattr[3] += $opt_days - $opt_offset; # day 
     446        my $stop_day = mktime(@timeattr); 
    456447 
    457448        for (my $i = 0; $i < ($unprocessed_programmes-1); $i++) { 
     
    496487                        printf "gap-fetching: including prog '%s', start %d, end %d\n", $unprocessed_progname[$i],  
    497488                                $unprocessed_starttime[$i], $unprocessed_starttime[$i+1] if $debug; 
     489                } elsif ($unprocessed_starttime[$i+1] <= $start_day or 
     490                                        $unprocessed_starttime[$i] >= $stop_day) { 
     491                        printf "skipping program because before or after requested days, '%s', start %d, end %d\n", 
     492                                         $unprocessed_progname[$i], $unprocessed_starttime[$i], $unprocessed_starttime[$i+1] if $debug; 
     493                        next; 
    498494                } 
    499495 
     
    555551        if ($stats{failed_to_fetch_portal_detail_page} >= 3 or $stats{failed_to_parse_portal_detail_page} >= 9) 
    556552        { 
    557                 &log("Skipping detail page because too many failures."); 
     553                &log("skipping detail page because too many failures."); 
    558554                return; 
    559555        } 
    560556 
    561557        my $seen_programme = 0; 
    562         my $data = Shepherd::Common::get_url(url => $url, debug => $debug); 
     558        my $data = Shepherd::Common::get_url(url => $url); 
    563559        my $tree = HTML::TreeBuilder->new_from_content($data) if ($data); 
    564560        if (!defined $tree) { 
     
    658654sub log 
    659655{ 
    660         my ($entry) = @_; 
    661         printf "%s\n", $entry; 
    662 } 
    663  
    664 ###################################################################################################### 
    665  
    666 sub print_stats 
    667 { 
    668         printf "STATS: %s v%s completed in %d seconds", $progname, $version, (time-$script_start_time); 
    669         foreach my $key (sort keys %stats) { 
    670                 printf ", %d %s",$stats{$key},$key; 
    671         } 
    672         printf "\n"; 
     656        &Shepherd::Common::log(@_); 
    673657} 
    674658 
     
    678662{ 
    679663        my ($xmlid,$url) = @_; 
    680         &log("fetching (weekly) station close data for $xmlid"); 
    681         my $data = Shepherd::Common::get_url(url => $url, debug => $debug); 
     664        &log("Fetching weekly 'Station Close' data for $xmlid"); 
     665        my $data = Shepherd::Common::get_url(url => $url); 
    682666        my $tree = HTML::TreeBuilder->new_from_content($data) if ($data); 
    683667 
     
    695679                        if (defined $last_td_text) { 
    696680                                        # 0=sec,1=min,2=hour,3=day,4=month,5=year,6=wday,7=yday,8=isdst 
    697                                         my @timeattr = localtime($starttime + (($daynum-1)*86400)); 
     681                                        my @timeattr = localtime($script_start_time + (($daynum-1)*86400)); 
    698682                                        $timeattr[0] = 0; # zero seconds 
    699683 
     
    717701                                                } 
    718702 
    719                                                 $station_close_data->{$xmlid}->[$daynum] = $found_time; 
     703                                                $timeattr[1] = 30; # min 
     704                                                $timeattr[2] = 4; # hours 4:30am 
     705                                                my $currtime = mktime(@timeattr); 
     706                                                my $cache_key = sprintf "%d,%d,%s,%s", $currtime, 0, $xmlid, "Station Close"; 
     707                                                $data_cache->{$cache_key} = $found_time; 
    720708 
    721709                                                printf "station close time for %s day %d is %s\n", 
  • status

    r825 r826  
    55grabber         yahoo7widget        1.88-r2 
    66grabber         rex                 3.5.5-r2 
    7 grabber         abc_website         3.08 
     7grabber         abc_website         3.09 
    88grabber         sbsnews_website     0.18 
    99grabber         oztivo              1.07