Rosetta Code/Rank languages by popularity: Difference between revisions
Rosetta Code/Rank languages by popularity (view source)
Revision as of 01:42, 19 May 2018
, 6 years ago→Perl 6: Using the API: Update to output sortable wikitables
Walterpachl (talk | contribs) m (→{{header|ooRexx}}: oops) |
Thundergnat (talk | contribs) (→Perl 6: Using the API: Update to output sortable wikitables) |
||
Line 3,214:
use URI::Escape;
use JSON::Fast;
use Sort::Naturally;
my $client = HTTP::UserAgent.new;
Line 3,219 ⟶ 3,220:
my $url = 'http://rosettacode.org/mw';
my $
my %counts =
mediawiki-query(
$url, 'pages',
Line 3,237 ⟶ 3,231:
:prop<categoryinfo>
)
.map({ .<title>.subst(/^'Category:'/, '') => .<categoryinfo><pages> || 0 });
my $out = open($tablefile, :w) or die "$!\n";
# Add table boilerplate and header
$out.say:
"\{|class=\"wikitable sortable\"\n",
"|+ As of { Date.today }\n",
"! Rank !! Language !! Count"
;
my @bg = <#fff; #ccc;>;
my $ff = 0;
my $rank = 1;
my $ties = 0;
# Get sorted unique task counts
for %counts.values.unique.sort: -* -> $count {
$ff++;
# Get list of tasks with this count
my @these = %counts.grep( *.value == $count )».keys.sort: *.&naturally;
for @these {
$
"|style=\"background-color: { @bg[$ff % 2] }\"|$rank\n"~
"|style=\"background-color: { @bg[$ff % 2] }\"|[[:Category:$_|]]\n"~
"|style=\"background-color: { @bg[$ff % 2] }\"|$count";
}
$rank += $ties;
$ties = 0;
}
$out.say( "|}\n" );
$out.close;
sub mediawiki-query ($site, $type, *%query) {
Line 3,276 ⟶ 3,284:
}</lang>
{{out|Abridged output}}
<div style="height:50em;overflow:scroll;">
{|class="wikitable sortable"
|+ As of 2018-05-18
! Rank !! Language !! Count
|-
|style="background-color: #ccc;"|1
|style="background-color: #ccc;"|[[:Category:Kotlin|Kotlin]]
|style="background-color: #ccc;"|1006
|-
|style="background-color: #fff;"|2
|style="background-color: #fff;"|[[:Category:Racket|Racket]]
|style="background-color: #fff;"|977
|-
|style="background-color: #ccc;"|3
|style="background-color: #ccc;"|[[:Category:Python|Python]]
|style="background-color: #ccc;"|960
|-
|style="background-color: #fff;"|4
|style="background-color: #fff;"|[[:Category:Perl 6|Perl 6]]
|style="background-color: #fff;"|945
|-
|style="background-color: #ccc;"|5
|style="background-color: #ccc;"|[[:Category:Tcl|Tcl]]
|style="background-color: #ccc;"|914
|-
|style="background-color: #fff;"|6
|style="background-color: #fff;"|[[:Category:C|C]]
|style="background-color: #fff;"|896
|-
|style="background-color: #ccc;"|7
|style="background-color: #ccc;"|[[:Category:J|J]]
|style="background-color: #ccc;"|888
|-
|style="background-color: #fff;"|8
|style="background-color: #fff;"|[[:Category:Zkl|Zkl]]
|style="background-color: #fff;"|878
|-
|style="background-color: #ccc;"|9
|style="background-color: #ccc;"|[[:Category:Java|Java]]
|style="background-color: #ccc;"|867
|-
|style="background-color: #fff;"|10
|style="background-color: #fff;"|[[:Category:D|D]]
|style="background-color: #fff;"|857
|-
|style="background-color: #ccc;"|11
|style="background-color: #ccc;"|[[:Category:Ruby|Ruby]]
|style="background-color: #ccc;"|846
|-
|style="background-color: #fff;"|12
|style="background-color: #fff;"|[[:Category:Go|Go]]
|style="background-color: #fff;"|838
|-
|style="background-color: #ccc;"|13
|style="background-color: #ccc;"|[[:Category:Haskell|Haskell]]
|style="background-color: #ccc;"|824
|-
|style="background-color: #fff;"|14
|style="background-color: #fff;"|[[:Category:REXX|REXX]]
|style="background-color: #fff;"|823
|-
|style="background-color: #ccc;"|15
|style="background-color: #ccc;"|[[:Category:Perl|Perl]]
|style="background-color: #ccc;"|794
|-
|style="background-color: #fff;"|16
|style="background-color: #fff;"|[[:Category:Julia|Julia]]
|style="background-color: #fff;"|774
|-
|style="background-color: #ccc;"|17
|style="background-color: #ccc;"|[[:Category:PicoLisp|PicoLisp]]
|style="background-color: #ccc;"|768
|-
|style="background-color: #fff;"|18
|style="background-color: #fff;"|[[:Category:Sidef|Sidef]]
|style="background-color: #fff;"|763
|-
|style="background-color: #ccc;"|19
|style="background-color: #ccc;"|[[:Category:Mathematica|Mathematica]]
|style="background-color: #ccc;"|723
|-
|style="background-color: #fff;"|20
|style="background-color: #fff;"|[[:Category:Phix|Phix]]
|style="background-color: #fff;"|682
|}
</div>
===Perl 6: Using web scraping===
|