User:AnomieBOT/source/tasks/WatchlistUpdater.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * New function to load a task (once). * Update the various scripts to use that function. * Update metadata for all tasks. SourceUploader: * Generate a new file, User:AnomieBOT/TaskList, since I keep forgetting
AnomieBOT (talk | contribs)
Updating published sources: General: * BREAKING CHANGE: And it's a big one: ** Data store changed from (binary) Storable to (readable) JSON. update-db.pl will change an existing database. This may affect the exact values storable in the permanent sto
Line 131:
my ($self, $api)=@_;
 
$api->task('WatchlistUpdater', 0, 10, qw(d::Util));
$api->read_throttle(0);
$api->edit_throttle(10);
 
my $endtime=time()+300;
Line 153 ⟶ 151:
);
if($res->{'code'} ne 'success'){
$selfapi->warn("Failed to retrieve last edit date for $page: ".$res->{'error'}."\n");
return 60;
}
$res=[values(%{$res->{'query'}{'pages'}})];
if(exists($res->[0]{'revisions'}[0]{'timestamp'})){
$data->{'lastrun'}=$selfapi->ISO2timestamp($res->[0]{'revisions'}[0]{'timestamp'});
} else {
$data->{'lastrun'}=0;
Line 170 ⟶ 168:
my $tok=$api->edittoken($page);
if($tok->{'code'} eq 'shutoff'){
$selfapi->warn("Task disabled: ".$tok->{'content'}."\n");
return 300;
}
if($tok->{'code'} ne 'success'){
$selfapi->warn("Failed to retrieve edit token for $page: ".$tok->{'error'});
return 60;
}
if(exists($tok->{'missing'})){
$selfapi->warn("Page $page does not exist");
$data->{'lastrun'}=time();
next;
Line 191 ⟶ 189:
my $res=$api->query([$data->{'gcontinue'}], %{$data->{'query'}}, %cont);
if($res->{'code'} ne 'success'){
$selfapi->warn("Failed to retrieve data for $page: ".$res->{'error'});
return 60;
}
Line 207 ⟶ 205:
@r=values %$res;
} else {
$selfapi->warn("Invalid data for $page: Not an array or hash ref");
return 60;
}
Line 238 ⟶ 236:
}
if($begin<0 || $end<0){
$selfapi->warn("Begin/end markers not found, refusing to edit $page\n");
} else {
substr($outtxt,$begin,$end-$begin)=$table;
if($intxt eq $outtxt){
$selfapi->warn("No update needed for $page\n");
} else {
my $res=$api->edit($tok, $outtxt, $data->{'summary'}, 0, $data->{'botflag'});
if($res->{'code'} ne 'success'){
$selfapi->warn("Write for $page failed: ".$res->{'error'});
next;
}
$selfapi->warn("Updated $page\n");
}
}