-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (46 loc) · 1.66 KB
/
main.py
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
44
45
46
47
48
49
50
51
52
53
import requests
# Replace with your personal access token
GITHUB_TOKEN = "YOUR-API-KEY"
USERNAME = "YOUR-USER-NAME"
# Headers with authorization
headers = {
"Authorization": f"token {GITHUB_TOKEN}",
"Accept": "application/vnd.github.v3+json"
}
# Function to get the list of repositories
def get_repositories(username):
url = f"https://api.github.com/users/{username}/repos"
response = requests.get(url, headers=headers)
if response.status_code == 200:
return [repo['name'] for repo in response.json()]
else:
print(f"Failed to fetch repositories: {response.status_code}")
return []
# Get repository traffic views
def get_repo_views(owner, repo):
url = f"https://api.github.com/repos/{owner}/{repo}/traffic/views"
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch views for {repo}: {response.status_code}")
return None
# Get repository traffic clones
def get_repo_clones(owner, repo):
url = f"https://api.github.com/repos/{owner}/{repo}/traffic/clones"
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch clones for {repo}: {response.status_code}")
return None
# Fetch repositories
repositories = get_repositories(USERNAME)
# Loop through the repositories and fetch traffic data
for repo in repositories:
views = get_repo_views(USERNAME, repo)
clones = get_repo_clones(USERNAME, repo)
print(f"Repository: {repo}")
print("Views:", views)
print("Clones:", clones)
print("-------------")