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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: ArticleCreationGrapher: * Fix image filename.
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.
 
(14 intermediate revisions by the same user not shown)
Line 1:
{{ombox|type=notice|text= ApprovalApproved requested2010-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.}}
<sourcesyntaxhighlight lang="perl">
package tasks::ArticleCreationGrapher;
 
Line 10 ⟶ 11:
Task: ArticleCreationGrapher
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 41
Status: BRFAInactive 2022-01-25
Created: 2010-08-25
 
Line 24 ⟶ 25:
use Data::Dumper;
use IPC::Open2;
use POSIXAnomieBOT::Task qw/strftime mktime:time/;
use AnomieBOT::Task;
use vars qw/@ISA/;
@ISA=qw/AnomieBOT::Task/;
 
my $epoch=2; # Increment this to force a new graph, e.g. if an improved version of gnuplot is installed
 
my @gnuplot=("/usr/bin/gnuplot");
Line 41 ⟶ 43:
graph => 'File:File-WikiProject Medicine - Dermatology task force - Articles created.svg',
size => [1000,600],
nextrunthumbsize => 0800,
graph_cats => [],
x2ticsettings => 'rotate by 0 scale 0.4',
x2tics => '',
},
);
Line 55 ⟶ 60:
 
=for info
ApprovalApproved requested2010-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 0-6;
}
 
Line 68 ⟶ 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){
myreturn 0 if $pgdata=$api->store->{$page->{'page'}} // {halting;
 
nextrun => 0,
# pages => {},Update
if ( exists( $api->store->{$page->{'page'}} ) ) {
};
#XXX next if my $pgdata=$api->store->{$page->{'nextrunpage'} > time()};
$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($nextrun > time() && ($api->store->{'epoch:'.$page->{'page'}}//0) >= $epoch);
$api->log( "Loading data to graph " . $page->{'page'} );
my $i=$api->iterator(
generator => 'categorymembers',
Line 90 ⟶ 105:
gcmlimit => 'max',
gcmnamespace => '0|1',
gcmtype => 'page',
prop => 'info',
inprop => 'subjectid',
Line 104 ⟶ 120:
my $ct=0;
foreach my $p (@pageids) {
return 0 if(exists( $pgdataapi->{'pages'}{$p})){halting;
if(exists($pages->{$p})){
push @px, $p;
next;
Line 110 ⟶ 127:
if($ct++>=100){
# periodic save
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
$ct=0;
}
Line 121 ⟶ 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 136 ⟶ 153:
next if $ts eq '';
$ts=$api->ISO2timestamp($ts);
$pgdatapages->{'pages'}{$p}={
t=>$ts,
r=>$is_redir,
Line 147 ⟶ 164:
};
}
$api->store->{'pg:'.$page->{'page'}}=$pgdatapages;
if(@px){
my %q=(
Line 163 ⟶ 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 181 ⟶ 199:
my $pid = open2(*R, *W, @gnuplot);
my ($w,$h)=@{$page->{'size'}};
my $range='["'.g_tt($pp[0]{'ts'}).'":"'.g_tt(time).'"]';
print W <<EOH ;
set terminal svg enhanced size $w $h font "DejaVu Sans"
Line 190 ⟶ 209:
 
set xdata time
set x2data time
set timefmt "%Y-%m"
set xtics nomirror out format "%b %Y"
 
set xrange $range
set x2range $range
EOH
myprint @t=localtimeW <<EOH if $pp[0]page->{x2tics} ne 'ts'};
set x2tics nomirror out $page->{x2ticsettings}
my $end=strftime('%Y-%m', localtime);
set x2tics ($page->{x2tics})
set grid x2tics
EOH
 
my @t=gmtime $pp[0]{'ts'};
my $end=strftime('%Y-%m', localtimegmtime);
my $x;
print W "set xtics (";
Line 200 ⟶ 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 235 ⟶ 265:
 
if($page->{'writepage'}){
$api->log( "Updating " . $page->{'page'} );
my $tok=$api->edittoken($page->{'page'});
if($tok->{'code'} eq 'shutoff'){
Line 244 ⟶ 275:
next;
}
my $txt="This is a compilation of article creation dates for $page->{for}\n\nThis page is generated by {{User|".$api->user."}} once a month. Last generated: ~~~~~\n\n[[$page->{graph}|".$page->{'sizethumbsize'}[0]."px|frameless|center|alt=Line graph of article and redirect creation dates by month]]\n\n{| class=\"wikitable\"\n! Article Created !! Article Title !! Type\n";
foreach my $p (@pp){
$txt.="|-\n| ".strftime('%F, %T', gmtime $p->{'ts'})." || [[:".$p->{'title'}."]] || ".($p->{'redir'}?'Redirect':'Article')."\n";
Line 263 ⟶ 294:
}
 
$api->log( "Uploading image file " . $page->{'graph'} . ' for ' . $page->{'page'} );
my $tok=$api->edittoken($page->{'graph'});
if($tok->{'code'} eq 'shutoff'){
Line 273 ⟶ 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 287 ⟶ 319:
next;
}
@t=localtimegmtime;
$pgdataapi->store->{'nextrunpg:'.$page->{'page'}}=mktime(0,0,0,1,$t[4]+1,$t[5])pages;
$api->store->{'epoch:'.$page->{'page'}}=$pgdataepoch;
$api->store->{'nextrun:'.$page->{'page'}}=timegm(0,0,0,1,$t[4]+1,$t[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 303 ⟶ 337:
}
 
# No more pages to check, try again in 10 minutes or so in case of errors.later
returnmy 600$t=undef;
foreach my $page (@pages){
my $nextrun=$api->store->{'nextrun:'.$page->{'page'}};
$t=$nextrun if(!defined($t) || $t>$nextrun);
}
myreturn $endtime=t-time()+600;
}
 
sub g_tt {
my @t=localtimegmtime shift;
return strftime('%Y-%m-%d', 0,0,0,1,$t[4],$t[5]);
}
 
Line 330 ⟶ 369:
if($dt ne $xx && $a!=$aa){
my @t=split(/-/,$dt);
my $dt2=strftime('%Y-%m-%d', 0,0,0,1,$t[1]-2,$t[0]-1900);
print $fh "$dt2 $aa\n" if(defined($pv) && $pv ne $dt2);
print $fh "$dt $a\n";
Line 344 ⟶ 383:
1;
 
</syntaxhighlight>
</source>