'gitea-languages-calculator.py' toevoegen
This commit is contained in:
parent
50571497c5
commit
00351e1a40
44
gitea-languages-calculator.py
Normal file
44
gitea-languages-calculator.py
Normal file
@ -0,0 +1,44 @@
|
||||
import requests
|
||||
|
||||
apiLocation = "https://git.tijl.dev/api/v1"
|
||||
secret = "token_here"
|
||||
|
||||
userrepos = requests.get(apiLocation+'/user/repos', headers={'Authorization': 'token '+secret})
|
||||
|
||||
if userrepos.status_code == 200:
|
||||
userrepos = userrepos.json()
|
||||
else:
|
||||
print(f'Request failed with status code {userrepos.status_code}')
|
||||
|
||||
result = []
|
||||
|
||||
for item in userrepos:
|
||||
|
||||
languages_url = item.get('languages_url')
|
||||
if languages_url:
|
||||
language_response = requests.get(languages_url, headers={'Authorization': 'token '+secret})
|
||||
if language_response.status_code == 200:
|
||||
language_data = language_response.json()
|
||||
newdata = {'full_name': item.get('full_name'), 'language_data': language_data}
|
||||
result.append(newdata)
|
||||
else:
|
||||
print(f'Request failed with status code {userrepos.status_code}')
|
||||
|
||||
language_counts = {}
|
||||
|
||||
for item in result:
|
||||
language_data = item.get('language_data')
|
||||
if language_data:
|
||||
for language, count in language_data.items():
|
||||
if language in language_counts:
|
||||
language_counts[language]['count'] += count
|
||||
else:
|
||||
language_counts[language] = {'count': count, 'score': 0}
|
||||
|
||||
for language in language_counts:
|
||||
language_counts[language]['score'] = language_counts[language]['count'] * len(language)
|
||||
|
||||
top_languages = sorted(language_counts, key=lambda x: language_counts[x]['count'], reverse=True)
|
||||
output = [{'language': language, 'top': index+1, 'score': language_counts[language]['score']} for index, language in enumerate(top_languages)]
|
||||
|
||||
print(output)
|
Loading…
Reference in New Issue
Block a user