Rosetta Code/List authors of task descriptions: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Update table) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: rearrange routines a bit, add links to author contributions) |
||
Line 281: | Line 281: | ||
use Sort::Naturally; |
use Sort::Naturally; |
||
use JSON::Fast; |
use JSON::Fast; |
||
⚫ | |||
my %cat = ( |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
my $ua = HTTP::UserAgent.new; |
my $ua = HTTP::UserAgent.new; |
||
for |
for %cat.keys -> $category |
||
{ # Get lists of Tasks & Draft Tasks |
{ # Get lists of Tasks & Draft Tasks |
||
#last; # Uncomment to skip this step |
#last; # Uncomment to skip this step |
||
Line 291: | Line 304: | ||
my $html = $ua.get($page).content; |
my $html = $ua.get($page).content; |
||
my $xmldoc = parse-html($html, :TAG<div>, :id<mw-pages>); |
my $xmldoc = parse-html($html, :TAG<div>, :id<mw-pages>); |
||
my @tasks = parse-html($xmldoc[0].Str, :TAG<li>).Str.comb( /'/wiki/' <-["]>+ / )».substr(6); # |
my @tasks = parse-html($xmldoc[0].Str, :TAG<li>).Str.comb( /'/wiki/' <-["]>+ / )».substr(6); #" |
||
my $f = open("./RC_{$category}.txt", :w) or die "$!\n"; |
my $f = open("./RC_{$category}.txt", :w) or die "$!\n"; |
||
note "Writing $category file..."; |
note "Writing $category file..."; |
||
Line 297: | Line 310: | ||
$f.close; |
$f.close; |
||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
note "Reading JSON hash file..."; |
note "Reading JSON hash file..."; |
||
my %tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( ); |
my %tasks = $hashfile.IO.e ?? $hashfile.IO.slurp.&from-json !! ( ); |
||
for |
for %cat.keys -> $category |
||
{ # Scrape info from each page. |
{ # Scrape info from each page. |
||
#last; # Uncomment to skip this step |
#last; # Uncomment to skip this step |
||
Line 322: | Line 324: | ||
%tasks{$title}{'category'} = %cat{$category}; |
%tasks{$title}{'category'} = %cat{$category}; |
||
# Otherwise skip if it has already been indexed. The creation date can't change |
# Otherwise skip if it has already been indexed. The creation date can't change |
||
# the task name *can* change, but it is |
# the task name *can* change, but it is exceedingly rare |
||
if %tasks{$title}{'title'}:exists { |
if %tasks{$title}{'title'}:exists { |
||
note $title; |
note $title; |
||
Line 332: | Line 334: | ||
# Filter out the actual history links |
# Filter out the actual history links |
||
$html.content ~~ m|'<li><span class="mw-history-histlinks">' (.+?) '</ul>'|; |
$html.content ~~ m|'<li><span class="mw-history-histlinks">' (.+?) '</ul>'|; #"' |
||
# Only interested in the oldest (last in the list) |
# Only interested in the oldest (last in the list) |
||
Line 348: | Line 350: | ||
# Parse out human readable title |
# Parse out human readable title |
||
$line ~~ m| '<a href="/mw/index.php?title=' $title '&' .+? 'title="'(<-["]>+)'"' |; # |
$line ~~ m| '<a href="/mw/index.php?title=' $title '&' .+? 'title="'(<-["]>+)'"' |; #' |
||
%tasks{$title}{'title'} = $0.Str; |
%tasks{$title}{'title'} = $0.Str; |
||
Line 376: | Line 378: | ||
# Add table boilerplate and header |
# Add table boilerplate and header |
||
$out.say( '<table border="1" cellpadding="4"><tr><th colspan="2">As of ', Date.today, ' | Total: ', |
$out.say( '<table border="1" cellpadding="4"><tr><th colspan="2">As of ', Date.today, ' | Total: ', |
||
"$count / Tasks: $taskcnt / Draft Tasks: $draftcnt", |
"$count / Tasks: $taskcnt / Draft Tasks: $draftcnt / By {+%tasks{*}».<author>.unique} Authors", |
||
'<tr><th>User</th><th>Authored</th></tr>' ); |
'<tr><th>User</th><th>Authored</th></tr>' ); |
||
# 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 { |
||
$out.print( |
$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 { |