forked from Max3kkk/repo-context-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage_ident.py
36 lines (27 loc) · 1.06 KB
/
language_ident.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
import os
import token
import requests
import json
def get_repo_languages(owner, repo, token):
url = f"https://api.github.com/repos/{owner}/{repo}/languages"
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
}
response = requests.get(url, headers=headers)
response.raise_for_status() # Raise an exception if the request was unsuccessful
data = response.json()
total_lines = sum(data.values())
data_percentage = {lang: (count / total_lines) * 100 for lang, count in data.items()}
return {lang: round(percentage, 2) for lang, percentage in data_percentage.items() if percentage >= 15}
def write_to_file(data, filename):
with open(filename, 'w') as file:
json.dump(data, file)
if __name__ == "__main__":
owner = os.getenv('OWNER')
repo = os.getenv('REPO')
token = os.getenv('GITHUB_TOKEN')
filename = "data/project_languages.json"
data = get_repo_languages(owner, repo, token)
write_to_file(data, filename)