-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_main_language.py
32 lines (28 loc) · 1.19 KB
/
get_main_language.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
import requests
def get_repo_languages(owner, repo):
# GitHub API URL for languages of a repository
url = f"https://api.github.com/repos/{owner}/{repo}/languages"
try:
# Send a GET request to the GitHub API
response = requests.get(url)
# Check for successful response
if response.status_code == 200:
languages = response.json()
if languages:
# Sort languages by byte size (largest first) and get the primary language
primary_language = max(languages, key=languages.get)
print(f"{primary_language}")
#print("All languages with byte usage:")
#for lang, bytes_used in languages.items():
# print(f"- {lang}: {bytes_used} bytes")
else:
print("No languages detected for this repository.")
else:
print(f"Failed to fetch languages: {response.status_code} {response.reason}")
except requests.RequestException as e:
print(f"Error during request: {e}")
# Example usage
# Replace 'owner' and 'repo' with the repository's owner and name
owner = "pytest-dev"
repo = "pytest"
get_repo_languages(owner, repo)