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

Content added Content deleted
m (Update table)
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;

# Friendlier descriptions for task categories
my %cat = (
'Programming_Tasks' => 'Task: ',
'Draft_Programming_Tasks' => 'Draft:'
);

# Month names for date manipulations
my %months = <January February March April May June July August
September October November December> Z=> 1..12;

my $hashfile = './RC_hash.json';
my $htmlfile = './RC_Authors.html';


my $ua = HTTP::UserAgent.new;
my $ua = HTTP::UserAgent.new;


for 'Programming_Tasks', 'Draft_Programming_Tasks' -> $category
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;
}
}

my %cat = ( # Friendlier descriptions for task categories
'Programming_Tasks' => 'Task: ',
'Draft_Programming_Tasks' => 'Draft:'
);
# Month names for date manipulations
my %months = <January February March April May June July August
September October November December> Z=> 1..12;

my $hashfile = './RC_hash.json';
my $htmlfile = './RC_Authors.html';


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 'Programming_Tasks', 'Draft_Programming_Tasks' -> $category
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 exceedinly rare
# 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 '&amp;' .+? 'title="'(<-["]>+)'"' |; #"'
$line ~~ m| '<a href="/mw/index.php?title=' $title '&amp;' .+? '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( '<tr><td><ul>[[User:', $author, '|', $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 {