Skip to content

Instantly share code, notes, and snippets.

@Qkessler
Created March 24, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qkessler/ac23b4b5ac03ca84aa622649056dd731 to your computer and use it in GitHub Desktop.
Save Qkessler/ac23b4b5ac03ca84aa622649056dd731 to your computer and use it in GitHub Desktop.
Get GH user's most popular repos
Repo = namedtuple('Repo', 'name stars forks')
from collections import namedtuple
def get_repo_stats(user, n=5):
repos = []
for repo in user.get_repos():
if repo.fork:
continue
repos.append(Repo(repo.name, repo.stargazers_count, 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