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

Content added Content deleted
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: Line 296:
my %tasks;
my %tasks;


# clear screen
#=begin skip update
run($*DISTRO.is-win ?? 'cls' !! 'clear');

#=begin update

note 'Retreiving task authors...';


for %cat.keys -> $category {
for %cat.keys -> $category {
Line 317: Line 322:
)}
)}
).map({
).map({
note $category,': ', .[0]<title>;
print "\b" x 150, ' ' x 150, "\b" x 150,
%tasks{.[0]<title>}{'category'} = %cat{$category};
1 + $++, ' ', $category,': ', .[0]<title>;
%tasks{.[0]<title>}{'author'} = .[0]<revisions>[0]<user>;
%tasks{.[0]<title>}<category> = %cat{$category};
%tasks{.[0]<title>}{'date'} = .[0]<revisions>[0]<timestamp>.subst(/'T'.+$/, '')
%tasks{.[0]<title>}<author> = .[0]<revisions>[0]<user>;
%tasks{.[0]<title>}<date> = .[0]<revisions>[0]<timestamp>.subst(/'T'.+$/, '')
}
}
);
)
}
}


# Save information to a local file
$hashfile.IO.spurt(%tasks.&to-json);
$hashfile.IO.spurt(%tasks.&to-json);


#=end skip update
#=end update


# Load information from local file
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( );
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( );


Line 347: Line 355:
# Get sorted unique list of task authors
# Get sorted unique list of task authors
for %tasks{*}».<author>.unique.sort(*.&naturally) -> $author {
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>" );
$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
# Get list of tasks by this author, sorted by name
for %tasks.grep( { $_.value.<author> eq $author } ).sort(*.key.&naturally) -> $task {
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>}",
$out.print( "<li>{$task.value.<date>} - {$task.value.<category>}",
" [[{uri-encode $task.key}|{$task.key}]]</li>"
" [[{uri-encode $task.key}|{$task.key}]]</li>"
);
)
}
}
$out.say( '</ol></ul></td></tr>' );
$out.say( '</ol></ul></td></tr>' );
Line 364: Line 376:
sub mediawiki-query ($site, $type, *%query) {
sub mediawiki-query ($site, $type, *%query) {
my $url = "$site/api.php?" ~ uri-query-string(
my $url = "$site/api.php?" ~ uri-query-string(
:action<query>, :format<json>, :formatversion(2), |%query);
:action<query>, :format<json>, :formatversion<2>, |%query);
my $continue = '';
my $continue = '';


Line 383: Line 395:
}
}
$str.subst(/<[\x00..\x7f]-[a..zA..Z0..9_.~-]>/, *.ord.fmt('%%%02X'), :g);
$str.subst(/<[\x00..\x7f]-[a..zA..Z0..9_.~-]>/, *.ord.fmt('%%%02X'), :g);
}</lang>
}
</lang>


;Sample output
;Sample output