-
-
Save svaksha/6a897aa91d7886ae2852 to your computer and use it in GitHub Desktop.
Script to find Julia developers in your area using the GitHub API
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
using HTTPClient: HTTPC | |
using JSON | |
# Fill in your city name and GitHub API token | |
const MEETUP_LOCATION = lowercase("Seattle") | |
const API_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
# Pages of search results to examine. Warning - you WILL hit the rate limit | |
const NUM_PAGES = 1 | |
typealias Field Union{AbstractString,Void} | |
type Guest | |
uid::Field | |
name::Field | |
email::Field | |
company::Field | |
end | |
typealias GuestList Array{Guest,1} | |
glist = GuestList() | |
Base.insert!(gl::GuestList, g::Guest) = begin | |
if findfirst((guest) -> guest.uid == g.uid, gl) == 0 | |
push!(gl, g) | |
end | |
end | |
# When the script exits, write guest list to CSV | |
atexit() do | |
f = open("guestlist.csv", "w") | |
header = join(map(string, fieldnames(Guest)),",") | |
lines = map((g) -> join(map((f) -> g.(f), fieldnames(g)), ','), glist) | |
unshift!(lines, header) | |
write(f, join(lines, '\n')) | |
close(f) | |
end | |
function apireq(url::AbstractString) | |
opts = RequestOptions(headers = [ | |
("User-Agent", "MeetupFinder"), | |
("Authorization", "token $API_TOKEN") | |
]) | |
res = bytestring(HTTPC.custom("https://api.github.com$url", "GET", opts).body.data) | |
if contains(res, "API rate limit exceeded") error("Rate limit exceeded") end | |
JSON.parse(res) | |
end | |
getrepos(page::Int64) = apireq("/search/repositories?q=jl+language:julia&page=$page")["items"] | |
REPOS = Dict[] | |
for i = 1:NUM_PAGES | |
REPOS = union(REPOS, getrepos(i)) | |
end | |
for r in REPOS | |
info("Checking contributors to $(r["full_name"])") | |
contribs = apireq("/repos/$(r["full_name"])/contributors") | |
for c in contribs | |
info("Checking location for $(c["login"])") | |
uinfo = apireq("/users/$(c["login"])") | |
if haskey(uinfo, "location") && uinfo["location"] != nothing | |
if contains(lowercase(uinfo["location"]), MEETUP_LOCATION) | |
insert!(glist, Guest(c["login"], uinfo["name"], uinfo["email"], uinfo["company"])) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment