Created
March 1, 2017 08:11
-
-
Save infinite-Joy/19baa9593c81c08cd84798d438e37afc to your computer and use it in GitHub Desktop.
a way to find the primary language preference of github users based on the primary language of the repos they contribute too. This assumes you have the guthub username or login name
This file contains 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
import requests | |
import json | |
import pprint | |
def user_name(json_string): | |
user = json.loads(str(json_string)) | |
return user.get("login") | |
def all_users(filename): | |
users = [] | |
with open(filename) as f: | |
users = [user_name(line) for line in f] | |
return users | |
def user_commits(user): | |
r = requests.get('https://api.github.com/users/%s/repos?client_id=XXXX&client_secret=YYYY' % user) | |
repos = json.loads(r.content) | |
return repos | |
def get_language(repo): | |
return repo.get("language", None) | |
def language_count(langs): | |
return {x: langs.count(x) for x in set(langs)} | |
def get_user_language(repos): | |
langs = [get_language(repo) for repo in repos] | |
return language_count(langs) | |
if __name__ == '__main__': | |
users = all_users("github_emails_data.jl") | |
import time | |
for user in users: | |
time.sleep(5) | |
user_repos = user_commits(user) | |
repo_languages = get_user_language(user_repos) | |
print(user, repo_languages) | |
with open("user_commits.out", "a+") as fw: | |
fw.write(", ".join([user, str(repo_languages)])) | |
fw.write("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment