Rosetta Code/Rank languages by popularity: Difference between revisions

Content added Content deleted
(→‎{{header|Ruby}}: re-write to remove limits on number of categories.)
(→‎{{header|Ruby}}: use the Programming_Languages category)
Line 460:
<lang ruby>require 'rosettacode'
 
categorieslangs = Hash.new(0)
module RosettaCode
RosettaCode.rc_tasks(category"Programming_Languages") do |tasklang|
def RosettaCode.rc_all_categories
sleep 1 # be# kinddon't tokill the server
query = {
lang = (lang.split(":"))[-1]
"action" => "query",
RosettaCode.rc_tasks(lang) do |task|
"list" => "allcategories",
langs[lang] += 1
"format" => "xml",
"aclimit" => 500,
}
categories = []
while true
url = rc_url "api.php", query
doc = REXML::Document.new open(url)
 
REXML::XPath.each(doc, "//c") do |category|
categories << category.text
end
 
continue = REXML::XPath.first(doc, "//query-continue")
break if continue.nil?
cm = REXML::XPath.first(continue, "allcategories")
query["acfrom"] = cm.attribute("acfrom").value
end
categories
end
end
 
$stdout.sync=true
 
categories = Hash.new(0)
RosettaCode.rc_all_categories.each do |category|
sleep 1 # be kind to the server
RosettaCode.rc_tasks(category) do |task|
categories[category] += 1
end
end
 
puts "There are #{categorieslangs.length} categorieslanguages"
puts "the top 10:"
categorieslangs.sort_by {|key,val| val}.reverse.each_with_index do |pair, i|
categorylang, count = pair
puts "#{i+1}. #{count} - #{categorylang}"
end</lang>
<pre>There are 571139 categorieslanguages
the top 10:
1. 313 - Tcl
2. 312270 - Programming TasksPython
3. 270236 - PythonAda
4. 236232 - AdaRuby
5. 232229 - RubyC
6. 229222 - CPerl
7. 222209 - PerlOCaml
8. 209206 - OCamlJava
9. 205200 - JavaHaskell
10. 200198 - HaskellALGOL 68</pre>
 
=={{header|Tcl}}==