Rosetta Code/List authors of task descriptions: Difference between revisions
Rosetta Code/List authors of task descriptions (view source)
Revision as of 20:36, 21 December 2017
, 6 years ago→{{header|Perl 6}}: Replaced accidentally overwritten code - Change to version using mediawiki API
Thundergnat (talk | contribs) (Update full list) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Replaced accidentally overwritten code - Change to version using mediawiki API) |
||
Line 273:
=={{header|Perl 6}}==
{{works with|Rakudo|2017.
The pseudocode above is no longer really useful as the page format has changed significantly
<lang perl6>use HTTP::UserAgent;
use
use Sort::Naturally;
# Friendlier descriptions for task categories
Line 290 ⟶ 287:
);
my $client = HTTP::UserAgent.new;
my $url = 'http://rosettacode.org/mw';
my $htmlfile = './RC_Authors.html';
my $hashfile = './RC_Authors.json';
my %tasks;
#=begin skip update
for %cat.keys -> $category {
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle("Category:$category"),
:gcmlimit<350>,
:rawcontinue(),
:prop<title>
).map({
mediawiki-query(
$url, 'pages',
:titles(.<title>),
:prop<revisions>,
:rvprop<user|timestamp>,
:rvstart<2000-01-01T01:01:01Z>,
)}
).map({
note $category,': ', .[0]<title>;
%tasks{.[0]<title>}{'category'} = %cat{$category};
%tasks{.[0]<title>}{'author'} = .[0]<revisions>[0]<user>;
%tasks{.[0]<title>}{'date'} = .[0]<revisions>[0]<timestamp>.subst(/'T'.+$/, '')
}
);
}
$hashfile.IO.spurt(%tasks.&to-json);
#=end skip update
%tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( );
# Convert saved task / author info to an HTML table
Line 390 ⟶ 352:
# and add them
$out.print( "<li>{$task.value.<date>} - {$task.value.<category>}",
" [[{uri-encode $task.key}|{$task.
);
}
Line 398 ⟶ 360:
$out.close;
sub mediawiki-query ($site, $type, *%query) {
my
:action<query>, :format<json>, :formatversion(2), |%query);
my $continue = '';
gather loop {
my $response = $client.get("$url&$continue");
my $data = from-json($response.content);
take $_ for $data.<query>.{$type}.values;
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last);
}
}
sub uri-query-string (*%fields) { %fields.map({ "{.key}={uri-encode .value}" }).join("&") }
sub uri-encode ($str) {
if $str ~~ /<:!ASCII>/ {
my $enc = $str.subst(/<[\x00..\x7f]-[a..zA..Z0..9_.~-]>/, *.ord.fmt('%%%02X'), :g);
return $enc.subst(/<:!ASCII-[\w]>/, *.Str.encode('utf8').list.fmt("%%%02X"), :g ).subst(' ','',:g);
}
$str.subst(/<[\x00..\x7f]-[a..zA..Z0..9_.~-]>/, *.ord.fmt('%%%02X'), :g);
}
</lang>
Line 408 ⟶ 388:
;Sample output
<table border="1" cellpadding="4"><tr><th colspan="2">As of 2017-
<tr><td><ul>[[User:2Powers|2Powers]] [[Special:Contributions/2Powers|?]]</ul></td><td><ul><ol><li>2013-05-16 - Draft: [[
<tr><td><ul>[[User:12.175.32.19|12.175.32.19]] [[Special:Contributions/12.175.32.19|?]]</ul></td><td><ul><ol><li>2009-11-12 - Task: [[Soundex|Soundex]]</li></ol></ul></td></tr>
<tr><td><ul>[[User:12Me21|12Me21]] [[Special:Contributions/12Me21|?]]</ul></td><td><ul><ol><li>2015-05-04 - Task: [[
<tr><td colspan='2'><br/> Many rows omitted... <br/></td></tr>
|