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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: SourceUploader: * Sort directory pages by last modified date. * Use <nowiki><syntaxhighlight></nowiki> instead of <nowiki><source></nowiki>. d::NoWiki: * Add support for <nowiki><syntaxhighlight></nowiki>. General: * Vario
AnomieBOT (talk | contribs)
Updating published sources: ArticleCreationGrapher: * Discontinue task. Graph doesn't seem to really be used anymore, and mw:Extension:Graph exists which would be a better way to do it than a monthly file upload.
 
(9 intermediate revisions by the same user not shown)
Line 1:
{{ombox|type=notice|text= Approved 2010-08-29<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 41]]}}
{{ombox|type=notice|text= Task discontinued 2022-01-25. The graph has trailed off, the page it's on hasn't been updated in years and gets minimal views, and we now have [[mw:Extension:Graph]] that can generate graphs from data instead of having to have an image uploaded monthly. If someone still wants such a graph, it would be better to have a bot create a data table somewhere to be graphed via that extension.}}
<syntaxhighlight lang="perl">
package tasks::ArticleCreationGrapher;
Line 10 ⟶ 11:
Task: ArticleCreationGrapher
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 41
Status: ApprovedInactive 20102022-0801-2925
Created: 2010-08-25
 
Line 28 ⟶ 29:
@ISA=qw/AnomieBOT::Task/;
 
my $epoch=12; # Increment this to force a new graph, e.g. if an improved version of gnuplot is installed
 
my @gnuplot=("/usr/bin/gnuplot");
Line 60 ⟶ 61:
=for info
Approved 2010-08-29<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 41]]
 
=for info
Task discontinued 2022-01-25. The graph has trailed off, the page it's on hasn't been updated in years and gets minimal views, and we now have [[mw:Extension:Graph]] that can generate graphs from data instead of having to have an image uploaded monthly. If someone still wants such a graph, it would be better to have a bot create a data table somewhere to be graphed via that extension.
 
=cut
 
sub approved {
return -6;
}
 
Line 72 ⟶ 76:
 
$api->task('ArticleCreationGrapher', 0, 10, qw/d::Timestamp/);
 
# Spend a max of 10 minutes on this task before restarting
my $endtime=time()+600;
 
foreach my $page (@pages){
return 0 if $api->halting;
 
my $pgdata=$api->store->{$page->{'page'}} // {
# nextrun => 0,Update
if ( exists( $api->store->{$page->{'page'}} pages) =>) {},
my $pgdata=$api->store->{$page->{'page'}} // {;
};
$api->store->{'epoch:'.$page->{'page'}} = $pgdata->{'epoch'} // 0;
$api->store->{'nextrun:'.$page->{'page'}} = $pgdata->{'nextrun'};
$api->store->{'pg:'.$page->{'page'}} = $pgdata->{'pages'};
delete( $api->store->{$page->{'page'}} );
};
 
my $nextrun = $api->store->{'nextrun:'.$page->{'page'}} // 0;
my $pages = $api->store->{'pg:'.$page->{'page'}} // {};
my @pp=();
if($nonet){
foreach my $v (values %{$pgdata->{'pages'}}){
next unless ref($v) eq 'HASH';
push @pp, { redir=>$v->{'r'}, ts=>$v->{'t'}, title=>$v->{'tt'} };
}
} else {
next if($pgdata->{'nextrun'} > time() && ($pgdataapi->store->{'epoch:'.$page->{'page'}}//0) >= $epoch);
$api->log( "Loading data to graph " . $page->{'page'} );
my $i=$api->iterator(
generator => 'categorymembers',
Line 95 ⟶ 105:
gcmlimit => 'max',
gcmnamespace => '0|1',
returngcmtype 0 if(time =>$endtime); 'page',
prop => 'info',
inprop => 'subjectid',
Line 110 ⟶ 121:
foreach my $p (@pageids) {
return 0 if $api->halting;
if(exists($pgdatapages->{'pages'}{$p})){
push @px, $p;
next;
Line 116 ⟶ 127:
if($ct++>=100){
# periodic save
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
$ct=0;
}
Line 127 ⟶ 138:
);
if($res->{'code'} eq 'shutoff'){
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
$api->warn("Task disabled: ".$res->{'content'}."\n");
return 300;
}
if($res->{'code'} ne 'success'){
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
$api->warn("Failed to get info for $p: ".$res->{'error'}."\n");
return 60;
Line 142 ⟶ 153:
next if $ts eq '';
$ts=$api->ISO2timestamp($ts);
$pgdatapages->{'pages'}{$p}={
t=>$ts,
r=>$is_redir,
Line 152 ⟶ 163:
ts=>$ts,
};
return 0 if(time>$endtime);
}
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
if(@px){
my %q=(
Line 170 ⟶ 180:
}
my $p=$_->{'pageid'};
$pgdatapages->{'pages'}{$p}{'r'}=exists($_->{'redirect'});
$pgdatapages->{'pages'}{$p}{'tt'}=$_->{'title'};
push @pp, {
title=>$_->{'title'},
redir=>$pgdatapages->{'pages'}{$p}{'r'},
ts=>$pgdatapages->{'pages'}{$p}{'t'},
};
}
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
}
}
$api->log( "Graphing data for " . $page->{'page'} );
@pp=sort {
my $x=($a->{'ts'} <=> $b->{'ts'});
Line 212 ⟶ 223:
 
my @t=gmtime $pp[0]{'ts'};
my $end=strftime('%Y-%m', @tgmtime);
my $x;
print W "set xtics (";
Line 218 ⟶ 229:
do {
$x=strftime('%Y-%m', 0,0,0,1,$t[4]++,$t[5]);
($t[4], $t[5]) = (1, $t[5]+1) if $t[4] == 13;
print W "," unless $f;
if($x=~/^(\d+)-01$/){
Line 253 ⟶ 265:
 
if($page->{'writepage'}){
$api->log( "Updating " . $page->{'page'} );
my $tok=$api->edittoken($page->{'page'});
if($tok->{'code'} eq 'shutoff'){
Line 281 ⟶ 294:
}
 
$api->log( "Uploading image file " . $page->{'graph'} . ' for ' . $page->{'page'} );
my $tok=$api->edittoken($page->{'graph'});
if($tok->{'code'} eq 'shutoff'){
Line 291 ⟶ 305:
}
my $comment="Updated graph";
my $txt="{{imbox|type=style|image=[[File:Ambox warning yellow.svg|50px]]|imageright=[[File:Crystal Clear action run.svg|50px]]|text=This image is automatically updated by a bot, {{User|".$api->user."}}. Any changes will be overwritten automatically.<center>'''Do not move this file to Wikimedia Commons.'''<br /><small>If for some reason you need to stop the bot, place {{tl|nobots}} on this page or post a message [[User:".$api->user."/shutoff/ArticleCreationGrapher|here]].</small></center>}}\n{{Information\n|description=Bot-generated graph of [[$page->{page}|$page->{for}]] article creation\n|source=Own work, created using [[Gnuplot]]\n|date=~~~~~\n|author={{User|".$api->operator."}} as the author of {{User|".$api->user."}}\n|permission={{PD-self|date=August 2010}}\n}}\n{{esoteric file}}\n\n[[Category:Wikipedia charts]]\n";
foreach my $c (@{$page->{'graph_cats'}}){
$txt.="[[Category:$c]]\n";
Line 306 ⟶ 320:
}
@t=gmtime;
$pgdataapi->store->{'epochpg:'.$page->{'page'}}=$epochpages;
$pgdataapi->store->{'nextrunepoch:'.$page->{'page'}}=timegm(0,0,0,1,$t[4]+1,$t[5])epoch;
$api->store->{'nextrun:'.$page->{'page'}}=timegm(0,0,0,1,$t[4]+1,$pgdatat[5]);
 
if(!exists($tok->{'missing'})){
$api->log( "Updating image description for " . $page->{'graph'} );
$res=$api->edit($tok, $txt, "Update page text", 0, 0);
if($res->{'code'} eq 'shutoff'){
Line 320 ⟶ 335:
}
}
return 0 if(time>$endtime);
}
 
Line 326 ⟶ 340:
my $t=undef;
foreach my $page (@pages){
my $pgdatanextrun=$api->store->{'nextrun:'.$page->{'page'}};
$t=$pgdata->{'nextrun'} if(!defined($t) || $t>$pgdata->{'nextrun'});
}
return $t-time();