Jump to content

Rosetta Code/Rank languages by popularity: Difference between revisions

PowerShell: Using MediaWiki API method
(Ranking updated)
(PowerShell: Using MediaWiki API method)
Line 4,059:
Rank: 9 (970 entries) C
Rank: 10 (960 entries) Zkl
</pre>
===PowerShell: Using MediaWiki API method===
{{trans|Python}}
<lang PowerShell>
$languages = @{}
$Body = @{
format = 'json'
action = 'query'
generator = 'categorymembers'
gcmtitle = 'Category:Programming Languages'
gcmlimit = '200'
gcmcontinue = ''
continue = ''
prop = 'categoryinfo'
}
$params = @{
Method = 'Get'
Uri = 'http://rosettacode.org/mw/api.php'
Body = $Body
}
while ($true) {
$response = Invoke-RestMethod @params
$response.query.pages.PSObject.Properties | ForEach-Object {
if (($_.value.PSObject.Properties.Name -Contains 'title') -and ($_.value.PSObject.Properties.Name -Contains 'categoryinfo')) {
$languages[$_.value.title.replace('Category:', '')] = $_.value.categoryinfo.size
}
}
if ($response.PSObject.Properties.Name -Contains 'continue') {
$gcmcontinue = $response.continue.gcmcontinue
$params.Body.gcmcontinue = $gcmcontinue
} else {
break
}
}
$members = $languages.GetEnumerator() | sort -Descending value
Get-Date -UFormat "Sample output on %d %B %Y at %R %Z"
$members | Select-Object -First 10 | foreach -Begin {$r, $rank, $count = 0, 0,-1} {
$r++
if ($count -ne $_.Members) {$rank = $r}
$count = $_.Value
$x = $_.Value.ToString("N0",[System.Globalization.CultureInfo]::CreateSpecificCulture('en-US'))
$entry = "($x entries)"
[String]::Format("Rank: {0,2} {1,15} {2}",$rank, $entry, $_.Name)
}
</lang>
{{out}}
<pre>
Sample output on 05 juillet 2022 at 19:53 +02
Rank: 1 (1,552 entries) Phix
Rank: 2 (1,545 entries) Wren
Rank: 3 (1,521 entries) Julia
Rank: 4 (1,498 entries) Go
Rank: 5 (1,497 entries) Raku
Rank: 6 (1,456 entries) Perl
Rank: 7 (1,402 entries) Nim
Rank: 8 (1,401 entries) Python
Rank: 9 (1,206 entries) C
Rank: 10 (1,180 entries) J
</pre>
 
678

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.