Skip to content

Instantly share code, notes, and snippets.

@iref
Created May 21, 2018 16:28
Show Gist options
  • Save iref/24a9a18c1e91a81c76a8d58af0325ca8 to your computer and use it in GitHub Desktop.
Save iref/24a9a18c1e91a81c76a8d58af0325ca8 to your computer and use it in GitHub Desktop.
Get GH user's most popular repos
from collections import namedtuple
Repo = namedtuple('Repo', 'name stars forks')
def get_repo_stats(user, n=5):
"""Takes a Github user object and returns the top n most popular repos by star count,
skips forks."""
repos = []
for repo in user.get_repos():
if repo.fork:
continue
repos.append(Repo(name=repo.name,
stars=repo.stargazers_count,
forks=repo.forks_count))
return sorted(repos, key=lambda x: x.stars, reverse=True)[:n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment