Skip to content

Instantly share code, notes, and snippets.

@BYK
Created July 11, 2011 07:42
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BYK/1075438 to your computer and use it in GitHub Desktop.
Save BYK/1075438 to your computer and use it in GitHub Desktop.
Get language stats of your GitHub
try:
import json
except ImportError:
import simplejson as json
import urllib
user = unicode(raw_input('Enter username: '))
repos = json.loads(urllib.urlopen(u'https://api.github.com/users/%s/repos?per_page=100' % user).read())
def reducer(stats, lang):
if lang:
stats[lang] = stats.setdefault(lang, 0) + 1
return whole
lang_stats = reduce(reducer, (repo["language"] for repo in repos), {})
lang_list_sorted = sorted(lang_stats, key=lambda l:lang_stats[l], reverse=True)
print(lang_list_sorted)
window.getLangStats = function getLangStats(repos) {
var mapper = function(ent){return ent.language},
reducer = function(stats, lang) {stats[lang] = (stats[lang] || 0) + 1; return stats},
langStats = repos.map(mapper).reduce(reducer, {});
delete langStats['null'];
return Object.keys(langStats).sort(function(a,b){return langStats[b] - langStats[a]});
};
window.ghApiCallHandler = function(result) {
if (Math.floor(result.meta.status/100) == 2)
alert(getLangStats(result.data).join(' >= '));
else
alert('Request failed with code ' + result.meta.status);
};
window.ghApiCall = function(user) {
var scrElm = document.createElement('script');
scrElm.src = 'https://api.github.com/users/' + encodeURI(user) + '/repos?callback=ghApiCallHandler&per_page=100';
(document.head || document.getElementsByTagName('head')[0]).appendChild(scrElm);
};
ghApiCall(prompt('Enter username'));
import scala.collection.mutable.HashMap
import scala.io.Source.fromInputStream
import scala.util.parsing.json.JSON
import java.net._
print("Enter username: ")
val urlFetcher = new URL("https://api.github.com/users/%s/repos?per_page=100".format(readLine()))
val repos = JSON.parseFull(fromInputStream(urlFetcher.openStream).getLines.mkString("\n")).get.asInstanceOf[List[Any]]
val langs = repos.map(_.asInstanceOf[Map[String, String]].get("language").get).filter(_ != null)
val langStats = new HashMap[String, Int]() {override def default(key:String) = 0}
for (lang <- langs) langStats(lang) += 1
print(langStats.keys.toList.sortBy(-langStats(_)).mkString(" >= "))
@ahmetb
Copy link

ahmetb commented Jul 28, 2011

abi calismani cok takdir ediyorum. cogzel mutis bisey. ama bunlar zaten http://resume.github.com/?ahmetalpbalkan altinda var biliyosun dimi?

@emres
Copy link

emres commented Jul 31, 2011

Ahmet, bence bu badge projesi bir tür 'minimal space constrained data visualization' gibi de görülebilir. Yani otomatik resume üretecinden farklı bir perspektifle ele alınabilir. (Tabii projeyi başlatanlar böyle bir perspektifi benimsemek zorunda değil, o ayrı ;-)

@bilelz
Copy link

bilelz commented Jan 9, 2023

Hello,
Today, you can get the statistics via this API https://api.github.com/repos/{owner}/{repo}/languages
Ex.: https://api.github.com/repos/bilelz/bilelz.github.io/languages

curl -o js/languages.json \
          --request GET  \
          --url https://api.github.com/repos/{owner}/{repo}/languages \
          --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
          --fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment