Last active
October 14, 2020 05:55
-
-
Save jiahao/ba62d6b307c26e8bc54b to your computer and use it in GitHub Desktop.
Creates a photo montage of Julia contributors using ImageMagick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Working version | |
using JSON | |
auth_token= #fill in to access Github API | |
function getcontribs(owner, repo, auth_token) | |
#Download information about contributors | |
page, authors=0, {} | |
while true #Download every page | |
page += 1 | |
url="https://api.github.com/repos/$owner/$repo/contributors?page=$(page)&access_token=$(auth_token)" | |
filename = download(url) | |
f=open(filename) | |
authorsonpage = JSON.parse(f) | |
close(f) | |
length(authorsonpage) > 0 || break | |
authors = [authors; authorsonpage] | |
end | |
authors | |
end | |
authors=getcontribs("JuliaLang", "julia", auth_token) | |
#Download everyone's gravatars | |
filenames = Dict() | |
for author in authors | |
filenames[author["login"]]=download(author["avatar_url"]) | |
end | |
# Get info about Julia packages | |
jl_usr_dir="/Users/jiahao/.julia/v0.3" | |
Packages = {} | |
for dir in readdir(string(jl_usr_dir, "/METADATA")) | |
urlfile = string(jl_usr_dir, "/METADATA/", dir, "/url") | |
if isfile(urlfile) | |
f=open(urlfile) | |
url=readline(f) | |
close(f) | |
owner, repo = split(url, '/')[4:5] | |
repo = split(repo, ".git")[1] | |
push!(Packages, (owner, repo)) | |
end | |
end | |
allpkgauthors={} | |
for (owner, repo) in Packages | |
pkgauthors=getcontribs(owner, repo, auth_token) | |
push!(allpkgauthors, pkgauthors...) | |
end | |
allauthlogins = union([(map(x->(x["login"],x["avatar_url"]), y)) | |
for y in (allpkgauthors, authors)]...) | |
#Download more gravatars | |
filenames = Dict() | |
for (login, url) in allauthlogins | |
haskey(filenames, login) || (filenames[login]=download(url)) | |
end | |
#Sum commits over all repos | |
contribcount = Dict() | |
for author in authors | |
contribcount[author["login"]] = author["contributions"] | |
end | |
for (login, url) in allauthlogins | |
for author in allpkgauthors | |
author["login"] == login || continue | |
if haskey(contribcount, login) | |
contribcount[login]+= author["contributions"] | |
else | |
contribcount[login] = author["contributions"] | |
end | |
end | |
end | |
contribcounts = collect(contribcount) | |
#Sort by most commits, then alphabetically | |
sort!(contribcounts, by=x->(x[2], x[1]), rev=true) | |
#Compute montage layout | |
aspectratio = 2//1 | |
ntiles=sqrt(length(contribcounts)/aspectratio) | |
ntilesx, ntilesy = iceil(aspectratio*ntiles), iceil(ntiles) | |
#Run ImageMagick's montage command | |
cmd = `montage` | |
for (login, contribs) in contribcounts | |
cmd = `$cmd -label "$login\n($contribs)" $(filenames[login])` | |
end | |
cmd = `$cmd -geometry 64x64+16+16 -tile $(ntilesx)x$ntilesy -font Calibri montage.jpg` | |
run(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment