yasserrmd commited on
Commit
b3895d7
·
verified ·
1 Parent(s): 2278df3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -54,18 +54,30 @@ def fetch_github_users(github_token=None, max_users=200, min_followers=10):
54
  if user_response.status_code == 200:
55
  user_data = user_response.json()
56
 
57
- # Fetch user's contribution data (public repos and events)
58
- events_url = f"https://api.github.com/users/{user['login']}/events/public"
59
  events_response = requests.get(events_url, headers=headers)
60
 
61
  contributions = 0
 
 
62
  if events_response.status_code == 200:
63
  events = events_response.json()
64
- # Count push events as contributions
65
- contributions = len([e for e in events if e.get('type') == 'PushEvent'])
66
-
67
- # Calculate total contributions
68
- total_contributions = contributions + user_data.get('public_repos', 0)
 
 
 
 
 
 
 
 
 
 
69
 
70
  all_users.append({
71
  'login': user_data.get('login', ''),
@@ -114,7 +126,7 @@ def fetch_github_users(github_token=None, max_users=200, min_followers=10):
114
  display_df.columns = ['Rank', 'Name', 'Username', 'Contributions', 'Followers', 'Public Repos', 'Location']
115
  display_df['GitHub Profile'] = df['login'].apply(lambda x: f"https://github.com/{x}")
116
 
117
- status_message = f"✅ Successfully fetched top {len(df)} contributors (sorted by contributions)\n" + "\n".join(status_updates[-5:])
118
  return display_df, status_message
119
  else:
120
  return pd.DataFrame(), "⚠️ No users found\n" + "\n".join(status_updates)
@@ -141,8 +153,8 @@ def search_users(df, search_term):
141
  with gr.Blocks(theme=gr.themes.Soft(), title="GitHub UAE Top Contributors") as app:
142
 
143
  gr.Markdown("""
144
- # 🏆 Top 200 GitHub Contributors in UAE
145
- ### Ranked by Total Contributions (Public Repos + Recent Push Events)
146
 
147
  **Note:** The app will automatically use `GITHUB_TOKEN` environment variable if set.
148
  Without a token, you're limited to 60 requests/hour. With a token: 5000 requests/hour.
@@ -200,9 +212,10 @@ with gr.Blocks(theme=gr.themes.Soft(), title="GitHub UAE Top Contributors") as a
200
  gr.Markdown("""
201
  ---
202
  **Ranking Criteria:**
203
- - **Primary Sort:** Total Contributions (Public Repos + Recent Push Events)
204
  - **Secondary Sort:** Followers count
205
  - Only users from UAE locations are included
 
206
 
207
  **How to set up GitHub Token:**
208
 
 
54
  if user_response.status_code == 200:
55
  user_data = user_response.json()
56
 
57
+ # Fetch user's contribution data for last 30 days
58
+ events_url = f"https://api.github.com/users/{user['login']}/events/public?per_page=100"
59
  events_response = requests.get(events_url, headers=headers)
60
 
61
  contributions = 0
62
+ thirty_days_ago = datetime.now() - timedelta(days=30)
63
+
64
  if events_response.status_code == 200:
65
  events = events_response.json()
66
+ # Count various contribution events from last 30 days
67
+ for event in events:
68
+ event_date = datetime.strptime(event.get('created_at', ''), '%Y-%m-%dT%H:%M:%SZ')
69
+ if event_date >= thirty_days_ago:
70
+ event_type = event.get('type', '')
71
+ # Count different types of contributions
72
+ if event_type == 'PushEvent':
73
+ # Count commits in push event
74
+ commits = event.get('payload', {}).get('commits', [])
75
+ contributions += len(commits) if commits else 1
76
+ elif event_type in ['PullRequestEvent', 'IssuesEvent', 'CreateEvent']:
77
+ contributions += 1
78
+
79
+ # Total contributions is based on last 30 days activity
80
+ total_contributions = contributions
81
 
82
  all_users.append({
83
  'login': user_data.get('login', ''),
 
126
  display_df.columns = ['Rank', 'Name', 'Username', 'Contributions', 'Followers', 'Public Repos', 'Location']
127
  display_df['GitHub Profile'] = df['login'].apply(lambda x: f"https://github.com/{x}")
128
 
129
+ status_message = f"✅ Successfully fetched top {len(df)} contributors (sorted by last 30 days contributions)\n" + "\n".join(status_updates[-5:])
130
  return display_df, status_message
131
  else:
132
  return pd.DataFrame(), "⚠️ No users found\n" + "\n".join(status_updates)
 
153
  with gr.Blocks(theme=gr.themes.Soft(), title="GitHub UAE Top Contributors") as app:
154
 
155
  gr.Markdown("""
156
+ # 🏆 Top 200 GitHub Contributors in UAE (Last 30 Days)
157
+ ### Ranked by Contributions in the Last 30 Days
158
 
159
  **Note:** The app will automatically use `GITHUB_TOKEN` environment variable if set.
160
  Without a token, you're limited to 60 requests/hour. With a token: 5000 requests/hour.
 
212
  gr.Markdown("""
213
  ---
214
  **Ranking Criteria:**
215
+ - **Primary Sort:** Contributions in Last 30 Days (Commits, Pull Requests, Issues, Creates)
216
  - **Secondary Sort:** Followers count
217
  - Only users from UAE locations are included
218
+ - Contributions counted: Commits (from PushEvents), Pull Requests, Issues, and Create Events
219
 
220
  **How to set up GitHub Token:**
221