Skip to content

Commit

Permalink
add separate star count program
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Mar 29, 2019
1 parent d33948f commit e5c2de2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 20 deletions.
35 changes: 35 additions & 0 deletions GithubStarTotal.py
@@ -0,0 +1,35 @@
#!/usr/bin/env python
"""
Totals up stars and fork count for all repos of a Github user.
Can use Oauth login if desired.
"""
import pandas as pd
from argparse import ArgumentParser
import gitutils.github_repo_stats as gu
import pandas


def main():
p = ArgumentParser(description='Totals up stars and fork count for all repos of a Github user.')
p.add_argument('user', help='Github username')
p.add_argument('oauth', help='Oauth filename', nargs='?')
p = p.parse_args()

counts = gu.repo_prober(p.user, p.oauth, None, True)[0]

dat = pd.DataFrame([c[1:] for c in counts],
index=[c[0] for c in counts],
columns=['forks', 'stars'])

datnz = dat[~(dat == 0).all(axis=1)]
# %% Stars and Forks
pd.set_option('display.max_rows', 500)

print(f'\n{p.user} total stars received {dat["stars"].sum()}')
print(f'{p.user} total other users forked {dat["forks"].sum()}\n')

print(datnz.sort_values(['stars', 'forks'], ascending=False))


if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -20,13 +20,13 @@ is showing which forks of your repos have had changes "ahead of" your code.
This shows your code is being improved, even if the forked repo didn't make a pull request.
I don't know of any other easy way out there to find this.

Count how many total GitHub stars an account has:
Count how many total GitHub stars a GitHub account has:

```sh
python ListAllGithubRepos.py githubusername oauth.key -stars
python GithubStarTotal.py username
```

That will take only a second or two even for large numbers of repos.
That will take a couple seconds even for large numbers of repos.

Also see Git [utilities](https://github.com/scivision/gitedu) for managing large (100+) numbers of users / teams, particularly for education and institutions.

Expand Down
33 changes: 16 additions & 17 deletions gitutils/github_repo_stats.py
Expand Up @@ -3,18 +3,18 @@
"""
from typing import Tuple, List
from time import sleep
import numpy as np
from pathlib import Path
import github
import logging
import pandas as pd

from .github_base import check_api_limit, github_session


def repo_prober(user: str, oauth: Path = None, branch: str = None,
def repo_prober(user: str,
oauth: Path = None,
branch: str = None,
starsonly: bool = False,
verbose: bool = False) -> Tuple[pd.DataFrame, List[Tuple[str, int]]]:
verbose: bool = False) -> Tuple[List[Tuple[str, int, int]], List[Tuple[str, int]]]:
"""
probe all GitHub repos for a user to see how much forks of each repo are ahead.
Discover if there is an actively developed fork of your GitHub repos
Expand All @@ -23,16 +23,18 @@ def repo_prober(user: str, oauth: Path = None, branch: str = None,
----------
user : str
GitHub username
oauth : pathlib.Path
oauth : pathlib.Path, optional
file containing GitHub Oauth hash
branch : str
branch : str, optional
Git branch to examine
verbose : bool
starsonly: bool, optional
far faster to only count forks and stars
verbose : bool, optional
verbosity
Results
-------
dat : pandas.DataFrame
counts : list of tuple of str, int, int
forks and stars for each repo
ahead : list of tuple of str, int
forked with repos with number of commits they're ahead of your repo
Expand All @@ -44,21 +46,18 @@ def repo_prober(user: str, oauth: Path = None, branch: str = None,
# %% prepare to loop over repos
repos = _get_repos(sess, user)

dat = pd.DataFrame(np.empty((len(repos), 2), int),
index=[r.name for r in repos],
columns=['forks', 'stars'])

counts = []
ahead: List[Tuple[str, int]] = []

for repo in repos:
for i, repo in enumerate(repos):
if not starsonly:
ahead += fork_prober(repo, sess, ahead, branch, verbose)

dat.loc[repo.name, :] = (repo.forks_count, repo.stargazers_count)
counts.append((repo.name, repo.forks_count, repo.stargazers_count))

check_api_limit(sess)

return dat, ahead
return counts, ahead


def fork_prober(repo, sess,
Expand All @@ -76,9 +75,9 @@ def fork_prober(repo, sess,
handle to GitHub session
ahead : list of tuple of str, int
forked with repos with number of commits they're ahead of your repo
branch : str
branch : str, optional
Git branch to examine
verbose : bool
verbose : bool, optional
verbosity
Results
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -61,6 +61,7 @@ console_scripts =
find_missing_file = find_missing_file:main
ActOnChanged = ActOnChanged:main
ListAllGithubRepos = ListAllGithubRepos:main
GithubStarTotal = GithubStarTotal:main
gitemail = gitemail:main

[flake8]
Expand Down

0 comments on commit e5c2de2

Please sign in to comment.