Created
May 21, 2018 16:28
-
-
Save iref/24a9a18c1e91a81c76a8d58af0325ca8 to your computer and use it in GitHub Desktop.
Get GH user's most popular repos
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
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