46 lines
1.5 KiB
Text
46 lines
1.5 KiB
Text
$define RCLANGS "https://rosettacode.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo&format=xml"
|
|
|
|
link strings
|
|
link hexcvt
|
|
|
|
procedure main(A)
|
|
limit := \A[1] # Limit the output?
|
|
cnt := create seq()
|
|
last := -1
|
|
every pair := !reverse(sort(langs := tallyPages(),2)) do {
|
|
n := if last ~=:= pair[2] then @cnt else (@cnt,"")
|
|
write(right(n,4),": ",left(pair[1],30,". "),right(pair[2],10,". "))
|
|
if 0 >= (\limit -:= 1) then break
|
|
}
|
|
write(*langs, " languages")
|
|
end
|
|
|
|
# Generate page counts for each language
|
|
procedure tallyPages()
|
|
counts := table()
|
|
continue := ""
|
|
while \(txt := ReadURL(RCLANGS||continue)) do {
|
|
txt ? {
|
|
while tab(find("<page ") & find(s := "title=\"Category:")+*s) do {
|
|
lang := tab(upto('"'))
|
|
tab(find(s := "pages=\"")+*s)
|
|
counts[lang] := numeric(tab(upto('"')))
|
|
}
|
|
continue := getContinue() | break
|
|
}
|
|
}
|
|
return counts
|
|
end
|
|
|
|
procedure getContinue()
|
|
gcm := "gcmcontinue="
|
|
return (tab(1),"&"||2(tab(find(gcm)),=gcm,="\"")||tab(upto('"')))
|
|
end
|
|
|
|
procedure ReadURL(url) #: read URL into string
|
|
page := open(url,"m-") | stop("Unable to open ",url,"\n",&errno,"->",&errortext)
|
|
if page["Status-Code"] < 300 then text := reads(page,-1)
|
|
else write(&errout,"ERROR: ",&errout," -> ",&errortext)
|
|
close(page)
|
|
return text
|
|
end
|