Content deleted Content added
Updating published sources: ArticleCreationGrapher: * New task. |
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. |
||
(15 intermediate revisions by the same user not shown) | |||
Line 1:
{{ombox|type=notice|text=
{{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.}}
<
package tasks::ArticleCreationGrapher;
Line 10 ⟶ 11:
Task: ArticleCreationGrapher
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 41
Status:
Created: 2010-08-25
Line 24 ⟶ 25:
use Data::Dumper;
use IPC::Open2;
use
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 39 ⟶ 41:
page_cats => [],
writepage => 0,
graph => 'File:File-WikiProject Medicine
size => [1000,600],
graph_cats => [],
x2ticsettings => 'rotate by 0 scale 0.4',
x2tics => '',
},
);
Line 55 ⟶ 60:
=for info
=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
}
Line 68 ⟶ 76:
$api->task('ArticleCreationGrapher', 0, 10, qw/d::Timestamp/);
my $endtime=time()+600;▼
foreach my $page (@pages){
▲ nextrun => 0,
#
if ( exists( $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 %
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
if(exists($pages->{$p})){
push @px, $p;
next;
Line 110 ⟶ 127:
if($ct++>=100){
# periodic save
$api->store->{'pg:'.$page->{'page'}}=$
$ct=0;
}
Line 121 ⟶ 138:
);
if($res->{'code'} eq 'shutoff'){
$api->store->{'pg:'.$page->{'page'}}=$
$api->warn("Task disabled: ".$res->{'content'}."\n");
return 300;
}
if($res->{'code'} ne 'success'){
$api->store->{'pg:'.$page->{'page'}}=$
$api->warn("Failed to get info for $p: ".$res->{'error'}."\n");
return 60;
Line 136 ⟶ 153:
next if $ts eq '';
$ts=$api->ISO2timestamp($ts);
$
t=>$ts,
r=>$is_redir,
Line 147 ⟶ 164:
};
}
$api->store->{'pg:'.$page->{'page'}}=$
if(@px){
my %q=(
Line 163 ⟶ 180:
}
my $p=$_->{'pageid'};
$
$
push @pp, {
title=>$_->{'title'},
redir=>$
ts=>$
};
}
$api->store->{'pg:'.$page->{'page'}}=$
}
}
$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
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 $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->{'
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=
$
$api->store->{'epoch:'.$page->{'page'}}=$
$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
foreach my $page (@pages){
my $nextrun=$api->store->{'nextrun:'.$page->{'page'}};
$t=$nextrun if(!defined($t) || $t>$nextrun);
}
}
sub g_tt {
my @t=
return strftime('%Y-%m
}
Line 330 ⟶ 369:
if($dt ne $xx && $a!=$aa){
my @t=split(/-/,$dt);
my $dt2=strftime('%Y-%m
print $fh "$dt2 $aa\n" if(defined($pv) && $pv ne $dt2);
print $fh "$dt $a\n";
Line 344 ⟶ 383:
1;
</syntaxhighlight>
|