Skip to content

Commit fe36ab9

Browse files
authored
Create update_clients.py
1 parent 73482d8 commit fe36ab9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

update_clients.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import json
2+
import requests
3+
4+
# Load the clients.json file
5+
with open('clients.json', 'r') as f:
6+
data = json.load(f)
7+
8+
# Function to extract the owner and repo name from a GitHub URL
9+
def extract_owner_and_repo(url):
10+
parts = url.replace("https://github.com/", "").split("/")
11+
return parts[0], parts[1]
12+
13+
# Function to get repo info from GitHub API
14+
def fetch_repo_info(owner, repo):
15+
url = f"https://api.github.com/repos/{owner}/{repo}"
16+
response = requests.get(url)
17+
if response.status_code == 200:
18+
repo_data = response.json()
19+
return repo_data['stargazers_count'], repo_data['forks_count']
20+
else:
21+
print(f"Failed to fetch data for {owner}/{repo}")
22+
return None, None
23+
24+
# Iterate through clients and update stars and forks
25+
for category in data:
26+
for client in data[category]:
27+
owner, repo = extract_owner_and_repo(client['repo'])
28+
stars, forks = fetch_repo_info(owner, repo)
29+
if stars is not None and forks is not None:
30+
client['repo_stars'] = stars
31+
client['repo_forks'] = forks
32+
else:
33+
client['repo_stars'] = 0
34+
client['repo_forks'] = 0
35+
36+
# Save the updated data back to clients.json
37+
with open('clients.json', 'w') as f:
38+
json.dump(data, f, indent=2)
39+
40+
print("Clients.json updated successfully!")

0 commit comments

Comments
 (0)