-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAAAA
43 lines (35 loc) · 1.51 KB
/
AAAA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
from datetime import datetime, timedelta
# GitHub credentials
GITHUB_USERNAME = "your_github_username"
GITHUB_TOKEN = "your_personal_access_token"
def get_contributions(username, token):
headers = {
"Authorization": f"token {token}"
}
# Get current year and one year ago
today = datetime.now()
one_year_ago = today - timedelta(days=365)
one_year_ago_iso = one_year_ago.strftime("%Y-%m-%dT%H:%M:%SZ")
# GitHub API endpoint for user repos
repos_url = f"https://api.github.com/users/{username}/repos"
response = requests.get(repos_url, headers=headers)
if response.status_code != 200:
print(f"Error: {response.json().get('message', 'Failed to fetch repositories')}")
return
repos = response.json()
contributed_repos = []
# Check commits for each repo
for repo in repos:
repo_name = repo["name"]
commits_url = f"https://api.github.com/repos/{username}/{repo_name}/commits?since={one_year_ago_iso}"
commits_response = requests.get(commits_url, headers=headers)
if commits_response.status_code == 200:
commits = commits_response.json()
if len(commits) > 0:
contributed_repos.append(repo_name)
else:
print(f"Error fetching commits for {repo_name}: {commits_response.json().get('message')}")
print(f"Repositories with contributions in the past year: {contributed_repos}")
# Call the function
get_contributions(GITHUB_USERNAME, GITHUB_TOKEN)