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