Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions get_traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@ def updateUserStats(self):
print(f">>> Getting repo details of user {user.name} with GitHub url : {user.html_url} ...")
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 All @@ -60,7 +65,7 @@ def updateUserStats(self):

def updateRepoStats(self, repo, results, idx):
row = [
repo.name,
repo.full_name,
repo.get_views_traffic()['count'],
repo.stargazers_count,
repo.watchers_count,
Expand Down