Skip to content

Commit a8c5daf

Browse files
committed
feat(projects): python script to fetch repo data
1 parent d665768 commit a8c5daf

File tree

2 files changed

+516
-0
lines changed

2 files changed

+516
-0
lines changed

get_repos.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import requests
2+
import json
3+
4+
ORG_NAME = 'metakgp'
5+
6+
def get_repositories(org_name):
7+
url = f'https://api.github.com/orgs/{org_name}/repos'
8+
9+
repos = []
10+
11+
response = requests.get(url, params={'sort':'updated', 'per_page': 100}) # we only have like 70 repos so don't need to handle pagination yet
12+
13+
if response.status_code != 200:
14+
print(f"Error fetching repositories: {response.status_code} - {response.text}")
15+
return repos
16+
17+
data = response.json()
18+
19+
for repo in data:
20+
repos.append({
21+
'name': repo['name'],
22+
'description': repo['description'],
23+
'stars': repo['stargazers_count'],
24+
'forks': repo['forks_count'],
25+
'language': repo['language']
26+
})
27+
28+
return repos
29+
30+
def save_to_json(data, filename):
31+
with open(filename, 'w') as json_file:
32+
json.dump(data, json_file, indent=4)
33+
print(f"Data saved to {filename}")
34+
35+
if __name__ == '__main__':
36+
repositories = get_repositories(ORG_NAME)
37+
save_to_json(repositories, "src/data/repo_data.json")
38+

0 commit comments

Comments
 (0)