Skip to content

Commit

Permalink
Restrict repos to those we have push access to
Browse files Browse the repository at this point in the history
There may be repositories on the user's list that they don't have push
access to. This will cause failures when retrieving statistics from them
as the API's require a higher level of permissions.
  • Loading branch information
lmprice committed Jul 24, 2019
1 parent b76a7aa commit 806d573
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions get_traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@ def updateUserStats(self):
repos = user.get_repos()

results = [None] * repos.totalCount
idx = 0

threads = []
for repo in repos:
# Spawn a thread for each repo
t = Thread(target=self.updateRepoStats, args=(repo,results,idx,))

# We're only able to retrieve repo statistics for those we can push to
repos = [repo for repo in repos if repo.permissions.push]
results = [None] * len(repos)

for idx, repo in enumerate(repos):
# Spawn a thread for each repo
t = Thread(target=self.updateRepoStats, args=(repo, results, idx,))
t.start()
threads.append(t)
idx += 1

# Wait for all threads to execute
while len(threads):
threads = [t for t in threads if t.is_alive()]

df = pd.read_csv(f'{self.user_name}.csv') if os.path.exists(f'{self.user_name}.csv') else pd.DataFrame(columns=['Repo', 'Views', 'Stars', 'Watching', 'Forks', 'Clones'])
if os.path.exists(f'{self.user_name}.csv'):
df = pd.read_csv(f'{self.user_name}.csv')
else:
df = pd.DataFrame(columns=['Repo', 'Views', 'Stars', 'Watching', 'Forks', 'Clones'])
changed = False
# Evaluate all repo results and update output CSV accordingly
for row in results:
Expand Down

0 comments on commit 806d573

Please sign in to comment.