58 lines
2 KiB
Text
58 lines
2 KiB
Text
$ include "seed7_05.s7i";
|
|
include "gethttp.s7i";
|
|
include "scanstri.s7i";
|
|
|
|
const type: popularityHash is hash [string] integer;
|
|
const type: rankingHash is hash [integer] array string;
|
|
|
|
const func array string: getLangs (in string: buffer) is func
|
|
result
|
|
var array string: langs is 0 times "";
|
|
local
|
|
var integer: pos is 0;
|
|
begin
|
|
pos := pos(buffer, "Category:");
|
|
while pos <> 0 do
|
|
pos +:= 9;
|
|
langs &:= buffer[pos .. pred(pos(buffer, '"', pos))];
|
|
pos := pos(buffer, "Category:", pos);
|
|
end while;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
local
|
|
var string: categories is "";
|
|
var popularityHash: popularity is popularityHash.value;
|
|
var rankingHash: ranking is rankingHash.value;
|
|
var array integer: numList is 0 times 0;
|
|
var string: lang is "";
|
|
var integer: pos is 0;
|
|
var string: numStri is "";
|
|
var integer: listIdx is 0;
|
|
var integer: index is 0;
|
|
var integer: place is 1;
|
|
begin
|
|
categories := getHttp("www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000");
|
|
for lang range getLangs(getHttp("rosettacode.org/mw/api.php?action=query&list=categorymembers&\
|
|
\cmtitle=Category:Programming_Languages&cmlimit=500&format=json")) do
|
|
pos := pos(categories, "title=\"Category:" & lang);
|
|
if pos <> 0 then
|
|
pos := pos(categories, "</a>", succ(pos));
|
|
if pos <> 0 then
|
|
pos := pos(categories, "(", succ(pos));
|
|
if pos <> 0 then
|
|
numStri := categories[succ(pos) len 10];
|
|
popularity @:= [lang] integer parse getDigits(numStri);
|
|
end if;
|
|
end if;
|
|
end if;
|
|
end for;
|
|
ranking := flip(popularity);
|
|
numList := sort(keys(ranking));
|
|
for listIdx range maxIdx(numList) downto minIdx(numList) do
|
|
for key index range ranking[numList[listIdx]] do
|
|
writeln(place lpad 3 <& ". " <& numList[listIdx] <& " - " <& ranking[numList[listIdx]][index]);
|
|
end for;
|
|
place +:= length(ranking[numList[listIdx]]);
|
|
end for;
|
|
end func;
|