Spaces:
Build error
Build error
Create repos.py
Browse files
repos.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from github import Github
|
| 2 |
+
from collections import Counter
|
| 3 |
+
from date import date_is_within_one_year
|
| 4 |
+
|
| 5 |
+
def top_ten_strings(strings):
|
| 6 |
+
"""
|
| 7 |
+
Counts occurrences of strings in a list and returns the top ten by count.
|
| 8 |
+
|
| 9 |
+
:param strings: List of strings to count.
|
| 10 |
+
:return: List of tuples containing the string and its count, sorted by count in descending order.
|
| 11 |
+
"""
|
| 12 |
+
# Count the occurrences of each string
|
| 13 |
+
string_counts = Counter(strings)
|
| 14 |
+
|
| 15 |
+
# Get the top 10 most common strings
|
| 16 |
+
top_ten = string_counts.most_common(10)
|
| 17 |
+
|
| 18 |
+
return top_ten
|
| 19 |
+
|
| 20 |
+
def sort_dict_by_value(d):
|
| 21 |
+
"""
|
| 22 |
+
Sorts a dictionary by its integer values in descending order and returns up to the first 10 items.
|
| 23 |
+
:param d: Dictionary with string keys and integer values.
|
| 24 |
+
:return: List of tuples containing the key and value, sorted by value in descending order.
|
| 25 |
+
"""
|
| 26 |
+
# Sort the dictionary by its values in descending order and take the first 10 items
|
| 27 |
+
sorted_items = sorted(d.items(), key=lambda item: item[1], reverse=True)[:5]
|
| 28 |
+
sorted_items = {el[0]: el[1] for el in sorted_items}
|
| 29 |
+
return sorted_items
|
| 30 |
+
|
| 31 |
+
def get_repo_info(username,token):
|
| 32 |
+
gh = Github(token)
|
| 33 |
+
user = gh.get_user(username)
|
| 34 |
+
repos = user.get_repos()
|
| 35 |
+
repocount = 0
|
| 36 |
+
gained_stars = 0
|
| 37 |
+
gained_forks = 0
|
| 38 |
+
topics = []
|
| 39 |
+
languages = {}
|
| 40 |
+
for repo in repos:
|
| 41 |
+
if date_is_within_one_year(repo.created_at):
|
| 42 |
+
repocount+=1
|
| 43 |
+
rep_topics = repo.get_topics()
|
| 44 |
+
gained_stars += repo.stargazers_count
|
| 45 |
+
gained_forks += repo.forks_count
|
| 46 |
+
for topic in rep_topics:
|
| 47 |
+
topics.append(topic)
|
| 48 |
+
langss = repo.get_languages()
|
| 49 |
+
for lang in langss:
|
| 50 |
+
if lang in languages:
|
| 51 |
+
languages[lang]+=langss[lang]
|
| 52 |
+
else:
|
| 53 |
+
languages.update({lang: langss[lang]})
|
| 54 |
+
top_10_topics = top_ten_strings(topics)
|
| 55 |
+
top_10_langs_abs = sort_dict_by_value(languages)
|
| 56 |
+
sum_langs = sum(list(languages.values()))
|
| 57 |
+
top_10_langs = {l: f"{round(top_10_langs_abs[l]*100/sum_langs,2)}%" for l in top_10_langs_abs}
|
| 58 |
+
return repocount, gained_stars, gained_forks, top_10_topics, top_10_langs
|