Task

Sort most popular programming languages based on the number of users on Rosetta Code.

Show the languages with at least 100 users.



A method to solve the task

Users of a computer programming language   X   are those referenced in the page:

 https://rosettacode.org/wiki/Category:X_User,     or preferably: 
 https://rosettacode.org/mw/index.php?title=Category:X_User&redirect=no to avoid re-directions. 

In order to find the list of such categories,   it's possible to first parse the entries of:

 http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000. 

Then download and parse each computer language   users   category to find the number of users of that computer language.



Sample output on 18 February 2019:

Language             Users
--------------------------
C                      391
Java                   276
C++                    275
Python                 262
JavaScript             238
Perl                   171
PHP                    167
SQL                    138
UNIX Shell             131
BASIC                  120
C sharp                118
Pascal                 116
Haskell                102
A Rosetta Code user usually declares using a language with the mylang template. This template is expected to appear on the User page. However, in some cases it appears in a user Talk page. It's not necessary to take this into account. For instance, among the 373 C users in the table above, 3 are actually declared in a Talk page.




""" Rank languages on Rosetta Code's site by number of users."""
 
using HTTP
using JSON3
 
const URI = "http://rosettacode.org/mw"
const PARAMS = [
    "action" => "query",
    "format" => "json",
    "formatversion" => "2",
    "generator" => "categorymembers",
    "gcmtitle" => "Category:Language users",
    "gcmlimit" => "999",
    "prop" => "categoryinfo",
    "rawcontinue" => "",
]
 
function mediawikiquery(site = URI, params = PARAMS, mintoshow = 100)
    langusers = Dict{String, Int}()
    url = site * "/api.php?" * join(map(x -> x[1] * "=" * x[2], params), "&")
    r = HTTP.get(url)
    data = JSON3.read(String(r.body))
    for page in data["query"]["pages"]
        lang = occursin("User", page["title"]) ? split(page["title"], r"\:|\sUser")[2] :
            page["title"]
        if haskey(page, "categoryinfo")
            langusers[lang] = page["categoryinfo"]["size"]
        else
            langusers[lang] = 0
        end
    end
    for (i, p) in enumerate(sort!([lp for lp in langusers], lt = (x, y) -> x[2] > y[2]))
        last(p) >= mintoshow && println(lpad(i, 2), "   ", rpad(first(p), 30), last(p))
    end
end
 
mediawikiquery()
 