-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgithub_data_retrieval.py
More file actions
80 lines (66 loc) · 2.48 KB
/
github_data_retrieval.py
File metadata and controls
80 lines (66 loc) · 2.48 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import requests
import json
# Repository details
REPO_OWNER = "Ze0ro99"
REPO_NAME = "PiMetaConnect"
# GitHub API Base URL
GITHUB_API_URL = "https://api.github.com"
# Headers for API requests (no authentication by default to stay within free limits)
HEADERS = {
"Accept": "application/vnd.github.v3+json"
}
# Function to fetch repository details
def get_repo_details():
url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}"
response = requests.get(url, headers=HEADERS)
if response.status_code == 200:
return response.json()
return {"error": response.json()}
# Function to fetch issues
def get_issues(state="open"):
url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/issues"
params = {"state": state}
response = requests.get(url, headers=HEADERS, params=params)
if response.status_code == 200:
return response.json()
return {"error": response.json()}
# Function to fetch pull requests
def get_pull_requests(state="open"):
url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/pulls"
params = {"state": state}
response = requests.get(url, headers=HEADERS, params=params)
if response.status_code == 200:
return response.json()
return {"error": response.json()}
# Function to fetch contributors
def get_contributors():
url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/contributors"
response = requests.get(url, headers=HEADERS)
if response.status_code == 200:
return response.json()
return {"error": response.json()}
# Function to format and print data
def format_and_print(data, title):
print(f"\n{'=' * 10} {title} {'=' * 10}")
if isinstance(data, list):
for item in data:
print(json.dumps(item, indent=4))
else:
print(json.dumps(data, indent=4))
# Main function to automate data retrieval and formatting
def main():
print(f"Automating data retrieval for repository: {REPO_OWNER}/{REPO_NAME}")
# Fetch and display repository details
repo_details = get_repo_details()
format_and_print(repo_details, "Repository Details")
# Fetch and display open issues
issues = get_issues()
format_and_print(issues, "Open Issues")
# Fetch and display open pull requests
pull_requests = get_pull_requests()
format_and_print(pull_requests, "Open Pull Requests")
# Fetch and display contributors
contributors = get_contributors()
format_and_print(contributors, "Contributors")
if __name__ == "__main__":
main()