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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: IMONumberRedirectCreator: * Category was apparently renamed, and no one told me or pointed out that the bot wasn't creating redirects anymore.
AnomieBOT (talk | contribs)
Updating published sources: IMONumberRedirectCreator: * Write conflicting numbers to User:AnomieBOT/IMO number conflicts
 
Line 71:
);
$self->{'iter'} = $iter;
$self->{'conflicts'} = {};
$self->{'doconflicts'} = 1;
}
 
Line 77 ⟶ 79:
if(!$n->{'_ok_'}) {
$api->warn("Failed to retrieve category members: " . $n->{'error'} . "\n");
$self->{'doconflicts'} = 0;
return 60;
}
Line 90 ⟶ 93:
if($tok->{'code'} eq 'shutoff') {
$api->warn("Task disabled: " . $tok->{'content'} . "\n");
$self->{'doconflicts'} = 0;
return 300;
}
if($tok->{'code'} ne 'success') {
$api->warn("Failed to get edit token for $title: " . $tok->{'error'} . "\n");
$self->{'doconflicts'} = 0;
next;
}
Line 106 ⟶ 111:
unless($txt=~/$redir\[\[\s*(.+?)\s*\]\]/) {
$api->log("Skipping $title: Not a redirect");
$self->{'conflicts'}{$title}{$target} = 1;
$self->{'conflicts'}{$title}{$title} = 1;
next;
}
Line 123 ⟶ 130:
if($res->{'code'} ne 'success') {
$api->warn("Could not resolve target page $target2: " . $res->{'error'} . "\n");
$self->{'doconflicts'} = 0;
return 60;
}
Line 141 ⟶ 149:
if($res->{'query'}{'redirects'}[0]{'to'} ne $target) {
$api->log("Skipping $title => $target: Already a double redirect to " . $res->{'query'}{'redirects'}[0]{'to'});
$self->{'conflicts'}{$title}{$target} = 1;
$self->{'conflicts'}{$title}{$target2} = 1;
next;
}
Line 147 ⟶ 157:
if(!exists($res->{'query'}{'normalized'}) || $res->{'query'}{'normalized'}[0]{'to'} ne $target) {
$api->log("Skipping $title => $target: Already a redirect to $target2");
$self->{'conflicts'}{$title}{$target} = 1;
$self->{'conflicts'}{$title}{$target2} = 1;
}
next;
Line 165 ⟶ 177:
}
 
if ( $self->{'doconflicts'} ) {
my %conflicts = %{$self->{'conflicts'}};
my $txt = "List of IMO numbers being claimed by multiple articles (via {{tl|IMO Number}} / [[:Category:IMO numbers]])\n\n";
$txt .= "This page is updated by a bot. Any changes will be overwritten periodically.\n\n";
if ( %conflicts ) {
for my $n (sort keys %conflicts) {
$txt .= "* [[$n]]: " . join( ', ', map { "[[$_]]" } sort keys %{$conflicts{$n}} ) . "\n";
}
} else {
$txt .= "There are no conflicts at this time.\n";
}
my $tok = $api->edittoken("User:AnomieBOT/IMO number conflicts", EditRedir => 1);
if($tok->{'code'} eq 'shutoff') {
$api->warn("Task disabled: " . $tok->{'content'} . "\n");
return 300;
}
if($tok->{'code'} ne 'success') {
$api->warn("Failed to get edit token for User:AnomieBOT/IMO number conflicts: " . $tok->{'error'} . "\n");
next;
}
if ( $txt ne ($tok->{'revisions'}[0]{'*'}//'') ) {
my $res=$api->edit($tok, $txt, "Updating list of IMO number conflicts. $screwup", 0, 1);
if($res->{'code'} ne 'success'){
$api->warn("Write for User:AnomieBOT/IMO number conflicts failed: " . $res->{'error'} . "\n");
return 60;
}
}
}
 
$self->{'iter'} = undef;
$self->{'conflicts'} = {};
return 3600 if !$self->{'doconflicts'};
$self->{'doconflicts'} = 0;
$api->store->{'lastrun'} = $starttime;
return $starttime + 86400 - time();