Rosetta Code/Rank languages by popularity: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: updated the number of languages.) |
(→{{header|zkl}}: replace with code using api) |
||
Line 4,976: | Line 4,976: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Using cURL and YAJL (yet anothe JSON library) libraries. |
|||
<lang zkl>host:="rosettacode.org"; port:=80; |
|||
dir:="/mw/index.php?title=Special:Categories&limit=5000"; |
|||
get:="GET %s HTTP/1.0\r\nHost: %s:%s\r\n\r\n".fmt(dir,host,port); |
|||
server:=Network.TCPClientSocket.connectTo(host,port); |
|||
server.write(get); // send request to web serer |
|||
data:=server.read(True); // read data from web server |
|||
data.println(); // size of response |
|||
This solution using the API as the web scraping URL is pretty slow. |
|||
data=data.filter(fcn(s){(not s.find("Omit")) and s.find("members") }); |
|||
I'm using JSON as format=txt has been deprecated. |
|||
data.println(); // size after a quick prune |
|||
<lang zkl>var [const] CURL=Import("zklCurl"), YAJL=Import("zklYAJL")[0]; |
|||
fcn getLangCounts(language){ // -->( (count,lang), ...) |
|||
re:=RegExp(0'|.+title="Category:([^"]+).+\((\d+) members|); |
|||
continueValue,tasks,curl := "",List(), CURL(); // "nm\0nm\0...." |
|||
r:=data.pump(List,'wrap(s){ if(not re.search(s)) return(Void.Skip); |
|||
do{ // eg 5 times |
|||
m:=re.matched; T(m[1],m[2].toInt()); |
|||
page:=curl.get(("http://rosettacode.org/mw/api.php?" |
|||
}); //-->( (name,#members) ...) |
|||
"format=json" |
|||
r.len().println(); // number of entries |
|||
"&action=query" |
|||
r.sort(fcn(a,b){a[1]>b[1]})[0,20] // sort, gimmie 20 and print |
|||
"&generator=categorymembers" |
|||
.pump(Console.println,fcn([(nm,n)],ref){ |
|||
"&gcmtitle=Category:Programming%%20Languages" |
|||
ref.inc(); "%3d w/%4d: %s".fmt(ref.value,n,nm) }.fp1(Ref(0)));</lang> |
|||
"&gcmlimit=500" |
|||
{{out}} |
|||
"&prop=categoryinfo" |
|||
<pre> |
|||
"&rawcontinue" // remove warning |
|||
Data(322,865) |
|||
"&gcmcontinue=%s") |
|||
Data(149,815) |
|||
.fmt(continueValue)); |
|||
1263 |
|||
page=page[0].del(0,page[1]); // get rid of HTML header |
|||
1 w/ 784: Tcl |
|||
json:=YAJL().write(page).close(); |
|||
2 w/ 749: Racket |
|||
3 w/ 731: Python |
|||
4 w/ 709: Programming Tasks |
|||
5 w/ 702: C |
|||
6 w/ 677: Perl 6 |
|||
7 w/ 669: J |
|||
8 w/ 664: D |
|||
9 w/ 658: Ruby |
|||
10 w/ 636: PicoLisp |
|||
11 w/ 629: Go |
|||
12 w/ 624: Perl |
|||
13 w/ 599: REXX |
|||
14 w/ 583: Ada |
|||
15 w/ 574: Haskell |
|||
16 w/ 567: Examples needing attention |
|||
17 w/ 567: Mathematica |
|||
18 w/ 548: AutoHotkey |
|||
19 w/ 547: WikiStubs |
|||
20 w/ 537: Unicon |
|||
</pre> |
|||
The optional part: Also read the programming languages from http://rosettacode.org/wiki/Category:Programming_Languages and use those to filter the data from http://rosettacode.org/mw/index.php?title=Special:Categories. |
|||
json["query"]["pages"].howza(9).pump(tasks,fcn(d){ #dictionary values,only |
|||
Here the fun part is the "optional" data is read in a thread so we have two web queries occurring at the same time. When the data is referenced, it forces the thread to complete but is very likely that the thread will finished by that time. |
|||
// { title:Category:AWK,categoryinfo:{ pages:398,size:401,... },... } |
|||
<lang zkl>const HOST="rosettacode.org", PORT=80; |
|||
// Gotta take care of no categoryinfo case |
|||
count:=d.find("categoryinfo",Dictionary).find("size",0); // or pages? |
|||
if(count<300) return(Void.Skip); // prune |
|||
T(count,d["title"].del(0,9)); |
|||
}); |
|||
if(continueValue=json.find("query-continue")) |
|||
cats:=fcn{ // read language names into a Dictionary in a thread |
|||
// subcat|524558580a52455858|4331 or void |
|||
dir:="/wiki/Category:Programming_Languages"; |
|||
continueValue=continueValue["categorymembers"]["gcmcontinue"]; |
|||
get:="GET %s HTTP/1.0\r\nHost: %s:%s\r\n\r\n".fmt(dir,HOST,PORT); |
|||
}while(continueValue); |
|||
server:=Network.TCPClientSocket.connectTo(HOST,PORT); |
|||
tasks |
|||
server.write(get); // send request to web serer |
|||
} |
|||
cats:=server.read(True); // read data from web server |
|||
langCounts:=getLangCounts() .sort(fcn(a,b){ a[0]>b[0] }); // reverse sort |
|||
cats.del(0,cats.find("</head>")); |
|||
cats=cats.filter("find",0'|title="Category:|); |
|||
re:=RegExp(0'|.+title="Category:([^"]+)|); |
|||
cats.pump(Void,fcn(s,re,d){ if(not re.search(s)) return(Void.Skip); |
|||
m:=re.matched; d.add(m[1],True);}.fp1(re,Dictionary())); |
|||
// the result of the pump is a Dictionary and |
|||
// is the function return value, ie the future value |
|||
}.future(); // doesn't need to finish until cats is referenced, way below |
|||
dir:="/mw/index.php?title=Special:Categories&limit=5000"; |
|||
get:="GET %s HTTP/1.0\r\nHost: %s:%s\r\n\r\n".fmt(dir,HOST,PORT); |
|||
server:=Network.TCPClientSocket.connectTo(HOST,PORT); |
|||
server.write(get); // send request to web serer |
|||
data:=server.read(True); // read data from web server |
|||
data.println(); // size of response |
|||
data = data.filter(fcn(s){(not s.find("Omit")) and s.find("members") }); |
|||
data.println(); // size after a quick prune |
|||
re:=RegExp(0'|.+title="Category:([^"]+).+\((\d+) members|); |
|||
r:=data.pump(List,fcn(s,re,cats){ if(not re.search(s)) return(Void.Skip); |
|||
m:=re.matched; if (not cats.find(m[1])) return(Void.Skip); |
|||
T(m[1],m[2].toInt()); |
|||
}.fp1(re,cats)); //-->( (name,#members) ...) |
|||
r.len().println(); |
|||
println("Most popular Rosetta Code languages as of ",Time.Date.prettyDay()); |
println("Most popular Rosetta Code languages as of ",Time.Date.prettyDay()); |
||
foreach n,name in ([1..15].zip(langCounts)) |
|||
r.sort(fcn(a,b){a[1]>b[1]})[0,20] // sort, gimmie 20 and print |
|||
{ println("%2d: %3d %s".fmt(n,name.xplode())) }</lang> |
|||
.pump(Console.println,fcn([(nm,n)],ref){ |
|||
ref.inc(); "%3d w/%4d: %s".fmt(ref.value,n,nm) }.fp1(Ref(0)));</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Most popular Rosetta Code languages as of Saturday, the 23rd of September 2017 |
|||
Data(337,900) |
|||
1: 957 Racket |
|||
Data(161,027) |
|||
2: 953 Python |
|||
522 = number of categories |
|||
3: 918 Tcl |
|||
Most popular Rosetta Code languages as of Wednesday, the 8th of April 2015 |
|||
4: 904 Perl 6 |
|||
1 w/ 849: Tcl |
|||
5: 877 J |
|||
2 w/ 839: Racket |
|||
6: 854 Zkl |
|||
3 w/ 835: Python |
|||
7: 840 Ruby |
|||
4 w/ 769: J |
|||
8: 828 C |
|||
5 w/ 765: Ruby |
|||
9: 812 Go |
|||
6 w/ 756: Perl 6 |
|||
10: 805 Haskell |
|||
7 w/ 748: C |
|||
11: 801 REXX |
|||
8 w/ 736: D |
|||
12: 800 Kotlin |
|||
9 w/ 733: Go |
|||
13: 788 Java |
|||
10 w/ 699: Perl |
|||
14: 776 Perl |
|||
11 w/ 683: PicoLisp |
|||
15: 755 D |
|||
12 w/ 678: REXX |
|||
13 w/ 655: Haskell |
|||
14 w/ 643: Java |
|||
15 w/ 638: Mathematica |
|||
16 w/ 620: Ada |
|||
17 w/ 589: AutoHotkey |
|||
18 w/ 582: Zkl |
|||
19 w/ 581: Unicon |
|||
20 w/ 539: Scala |
|||
</pre> |
</pre> |
||
{{omit from|Batch File}} |
{{omit from|Batch File}} |