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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: DatedCategoryCreater: * Approved!
AnomieBOT (talk | contribs)
Updating published sources: DatedCategoryCreater: * Supplemental BRFA approved! The bot may now date categories in Category:Wikipedia categories sorted by month.
Line 1:
{{ombox|type=notice|text= Approved 2012-05-30.<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 64]]}}
{{ombox|type=notice|text= Supplemental BRFA approved 2012-06-04.<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 65]]}}
<syntaxhighlight lang="perl">
package tasks::DatedCategoryCreator;
Line 11 ⟶ 12:
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 64
Status: Approved 2012-05-30
+BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 65
+Status: Approved 2012-06-04
Created: 2012-05-07
 
Create needed categories under [[:Category:Wikipedia maintenance categories sorted by month]] and [[:Category:Wikipedia categories sorted by month]].
 
=end metadata
Line 66 ⟶ 69:
=for info
Approved 2012-05-30.<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 64]]
 
=for info
Supplemental BRFA approved 2012-06-04.<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 65]]
 
=cut
Line 75 ⟶ 81:
sub run {
my ($self, $api)=@_;
my ($res, $iter);
 
$api->task('DatedCategoryCreator',0,0,qw/d::Talk d::Redirects d::Templates/);
Line 81 ⟶ 87:
my %did=();
 
my $curmonth=strftime('%B %Y', gmtime(time()+30*86400));
 
$yearre=join('|', 2004 .. ((gmtime(time()+86400))[5]+1900));
Line 87 ⟶ 93:
 
# Part 1: Create needed categories for the current month
for my $cat ('Wikipedia gcmtitle categories sorted by =>month', 'Category:Wikipedia maintenance categories sorted by month',){
$res=$api->query(
generator $res=$api-> 'categorymembers',query(
generator => 'categorymembers',
gcmtitle => 'Category:Wikipedia maintenance categories sorted by month',
gcmnamespace gcmtitle => 14"Category:$cat",
gcmtype gcmnamespace => 'subcat'14,
gcmlimit gcmtype => 'maxsubcat',
gcmlimit => 'max',
);
);
if($res->{'code'} ne 'success'){
$api->warn("Failed to get listmembers of maintenance categories sorted by month$cat: ".$res->{'error'}."\n");
return 60;
}
my $iter=$api->iterator(
titles => bunchlist(500, map monthly_for_cat($_->{'title'}, $curmonth), values %{$res->{'query'}{'pages'}}),
);
while($_=$iter->next){
return 0 if $api->halting;
 
if(!$_->{'_ok_'}){
$api->warn("Failed to retrieve members in ".$iter->iterval.": ".$_->{'error'}."\n");
return 60;
}
$resiter=$api->queryiterator(
titles => bunchlist(500, map monthly_for_cat($_->{'title'}, $curmonth), values %{$res->{'query'}{'pages'}}),
);
while($_=$iter->next){
return 0 if $api->halting;
 
next unless exists if(!$_->{'missing_ok_'});{
$api->warn("Failed to retrieve members in ".$iter->iterval.": ".$_->{'error'}."\n");
return 60;
}
 
$did{ next unless exists($_->{'titlemissing'}}=1);
 
$res=$self->make_dated_cat($api, $_->{'title'}, 'current month');
return $res if $did{$res_->{'title'}}=1;
$res=$self->make_dated_cat($api, $_->{'title'}, 'current month');
return $res if $res;
}
}
 
Line 175 ⟶ 183:
titles => "Category:$parent",
prop => 'categories',
clcategories => 'Category:Wikipedia maintenance categories sorted by month|Category:Wikipedia categories sorted by month',
);
if($res->{'code'} ne 'success'){
Line 186 ⟶ 194:
return 0;
}
my $type;
unless(grep $_->{'title'} eq 'Category:Wikipedia maintenance categories sorted by month', @{$res->{'categories'}}){
if(grep $api_->warn("Did not create category ${'title,'} because parent category $parent is not ineq 'Category:Wikipedia maintenance categories sorted by month"', @{$res->{'categories'}});{
$type='maintenance category';
unless} elsif(grep $_->{'title'} eq 'Category:Wikipedia maintenance categories sorted by month', @{$res->{'categories'}}){
$type='category';
} else {
$api->warn("Did not create category $title, because parent category $parent is not in Category:Wikipedia maintenance categories sorted by month or Category:Wikipedia categories sorted by month");
return 0;
}
Line 207 ⟶ 220:
return 0 unless exists($tok->{'missing'});
 
$api->log("Creating monthly dated maintenance category$type for $for in $title");
my $r=$api->edit($tok, $txt, "Creating monthly dated maintenance category$type for $for", 1, 1);
if($r->{'code'} ne 'success'){
$api->warn("Write failed on $title: ".$r->{'error'}."\n");