Skip to content

Instantly share code, notes, and snippets.

@lovesh
Created April 8, 2021 13:52
Show Gist options
  • Save lovesh/cac43abc701d0c30dd7d54b8ff41c9c0 to your computer and use it in GitHub Desktop.
Save lovesh/cac43abc701d0c30dd7d54b8ff41c9c0 to your computer and use it in GitHub Desktop.
Python 3 script to get users interacting with github repos
import urllib.request, json
# Will get users interacting with these repos
repositories = [
'docknetwork/sdk',
'docknetwork/dock-substrate',
'docknetwork/rify',
'docknetwork/vc-api',
'docknetwork/vcdm-verifier',
'docknetwork/price-feed-adapter',
'docknetwork/certs',
'docknetwork/token-migration',
]
# Get JSON data from a URL
def get_json(url):
with urllib.request.urlopen(url) as u:
return json.loads(u.read().decode())
# Get usernames of people who either contributed (code, issue, PR), starred or forked
def get_unique_users(repos):
usernames = set()
for repo in repos:
contributors_url = 'https://api.github.com/repos/{}/contributors'.format(repo)
issues_url = 'https://api.github.com/repos/{}/issues'.format(repo)
pulls_url = 'https://api.github.com/repos/{}/pulls'.format(repo)
stargazers_url = 'https://api.github.com/repos/{}/stargazers'.format(repo)
forkers_url = 'https://api.github.com/repos/{}/forks'.format(repo)
contributors = get_json(contributors_url)
for contributor in contributors:
usernames.add(contributor['login'])
issues = get_json(issues_url)
for issue in issues:
usernames.add(issue['user']['login'])
pulls = get_json(pulls_url)
for pull in pulls:
usernames.add(pull['user']['login'])
stargazers = get_json(stargazers_url)
for stargazer in stargazers:
usernames.add(stargazer['login'])
forkers = get_json(forkers_url)
for forker in forkers:
usernames.add(forker['owner']['login'])
return usernames
if __name__ == "__main__":
users = get_unique_users(repositories)
print('Got {} unique users'.format(len(users)))
print(users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment