Rosetta Code/List authors of task descriptions: Difference between revisions

m
→‎{{header|Perl 6}}: Add comments, style tweaks, minor enhancements
m (→‎{{header|Perl 6}}: Replaced accidentally overwritten code - Change to version using mediawiki API)
m (→‎{{header|Perl 6}}: Add comments, style tweaks, minor enhancements)
Line 296:
my %tasks;
 
# clear screen
#=begin skip update
run($*DISTRO.is-win ?? 'cls' !! 'clear');
 
#=begin skip update
 
note 'Retreiving task authors...';
 
for %cat.keys -> $category {
Line 317 ⟶ 322:
)}
).map({
noteprint $category"\b" x 150, ': ' x 150, .[0]<title>;"\b" x 150,
%tasks{ 1 + $++, ' ', $category,': ', .[0]<title>}{'category'} = %cat{$category};
%tasks{.[0]<title>}{'author'}<category> = .[0]<revisions>[0]<user>%cat{$category};
%tasks{.[0]<title>}{'date'}<author> = .[0]<revisions>[0]<timestampuser>.subst(/'T'.+$/, '');
%tasks{.[0]<title>}<date> = .[0]<revisions>[0]<timestamp>.subst(/'T'.+$/, '')
}
);
}
 
# Save information to a local file
$hashfile.IO.spurt(%tasks.&to-json);
 
#=end skip update
 
# Load information from local file
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( );
 
Line 347 ⟶ 355:
# Get sorted unique list of task authors
for %tasks{*}».<author>.unique.sort(*.&naturally) -> $author {
 
# Add author and contributions link to the first cell
$out.print( "<tr><td><ul>[[User:$author|$author]] [[Special:Contributions/$author|?]]</ul></td><td><ul><ol>" );
 
# Get list of tasks by this author, sorted by name
for %tasks.grep( { $_.value.<author> eq $author } ).sort(*.key.&naturally) -> $task {
 
# and add them
# and add the date, status and task link to the list in the second cell
$out.print( "<li>{$task.value.<date>} - {$task.value.<category>}",
" [[{uri-encode $task.key}|{$task.key}]]</li>"
);
}
$out.say( '</ol></ul></td></tr>' );
Line 364 ⟶ 376:
sub mediawiki-query ($site, $type, *%query) {
my $url = "$site/api.php?" ~ uri-query-string(
:action<query>, :format<json>, :formatversion(<2)>, |%query);
my $continue = '';
 
Line 383 ⟶ 395:
}
$str.subst(/<[\x00..\x7f]-[a..zA..Z0..9_.~-]>/, *.ord.fmt('%%%02X'), :g);
}</lang>
}
</lang>
 
;Sample output
10,333

edits