Files

37 lines
1.0 KiB
Python

import requests
import yaml
import json
def get_github_language_data():
raw_url = "https://raw.githubusercontent.com/github-linguist/linguist/master/lib/linguist/languages.yml"
output_file = "languages.json"
print("Fetching data from GitHub...")
try:
response = requests.get(raw_url)
response.raise_for_status()
full_data = yaml.load(response.text, Loader=yaml.SafeLoader)
clean_data = []
for lang_name, attr in full_data.items():
if 'color' in attr:
clean_data.append({
"name": lang_name,
"color": attr.get('color'),
"extensions": attr.get('extensions', [])
})
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(clean_data, f, indent=4)
print(f"Successfully saved {len(clean_data)} languages to {output_file}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
get_github_language_data()