From 806d5737cf27fc7f65e9b2a899c45da5c632c712 Mon Sep 17 00:00:00 2001 From: Michael Price Date: Wed, 24 Jul 2019 19:57:46 +0100 Subject: [PATCH] Restrict repos to those we have push access to 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. --- get_traffic.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/get_traffic.py b/get_traffic.py index 50f73ee..531cf3b 100644 --- a/get_traffic.py +++ b/get_traffic.py @@ -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: