mirror of
https://github.com/mustbeperfect/definitive-opensource.git
synced 2026-04-19 00:54:20 +02:00
Ran ruff format
This commit is contained in:
@@ -1,27 +1,29 @@
|
||||
import json
|
||||
|
||||
def slugify(name):
|
||||
|
||||
def slugify(name):
|
||||
return name.lower().replace(" ", "-").replace("(", "").replace(")", "")
|
||||
|
||||
def extract_repo_path(link):
|
||||
|
||||
def extract_repo_path(link):
|
||||
parts = link.rstrip("/").split("/")
|
||||
if len(parts) >= 5:
|
||||
return f"{parts[-2]}/{parts[-1]}"
|
||||
return ""
|
||||
|
||||
|
||||
def format_stars(n):
|
||||
if n >= 1_000_000:
|
||||
formatted = f"{n/1_000_000:.1f}M"
|
||||
return formatted.replace('.0M', 'M')
|
||||
formatted = f"{n / 1_000_000:.1f}M"
|
||||
return formatted.replace(".0M", "M")
|
||||
elif n >= 1_000:
|
||||
formatted = f"{n/1_000:.1f}k"
|
||||
return formatted.replace('.0k', 'k')
|
||||
formatted = f"{n / 1_000:.1f}k"
|
||||
return formatted.replace(".0k", "k")
|
||||
else:
|
||||
return str(n)
|
||||
|
||||
'''
|
||||
|
||||
|
||||
"""
|
||||
def format_stars(n):
|
||||
if n >= 1_000_000:
|
||||
value = n / 1_000_000
|
||||
@@ -37,10 +39,10 @@ def format_stars(n):
|
||||
return f"{int(value)}{suffix}"
|
||||
else:
|
||||
return f"{value:.1f}{suffix}"
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
def generate_contents(platform="all"):
|
||||
|
||||
with open("core/data/static/categories.json", "r", encoding="utf-8") as f:
|
||||
cat_data = json.load(f)
|
||||
with open("core/data/dynamic/applications.json", "r", encoding="utf-8") as f:
|
||||
@@ -48,28 +50,30 @@ def generate_contents(platform="all"):
|
||||
with open("core/data/static/tags.json", "r", encoding="utf-8") as f:
|
||||
tags_data = json.load(f)
|
||||
with open("core/data/static/platforms.json", "r", encoding="utf-8") as f:
|
||||
platforms_data = json.load(f)
|
||||
|
||||
platforms_data = json.load(f)
|
||||
|
||||
categories = cat_data.get("categories", [])
|
||||
subcategories = cat_data.get("subcategories", [])
|
||||
applications = app_data.get("applications", [])
|
||||
|
||||
|
||||
parent_map = {cat["id"]: cat["name"] for cat in categories}
|
||||
attribute_map = {attribute["id"]: attribute["emoji"] for attribute in tags_data["attributes"]}
|
||||
property_map = {property["id"]: property["name"] for property in tags_data["properties"]}
|
||||
attribute_map = {
|
||||
attribute["id"]: attribute["emoji"] for attribute in tags_data["attributes"]
|
||||
}
|
||||
property_map = {
|
||||
property["id"]: property["name"] for property in tags_data["properties"]
|
||||
}
|
||||
platform_map = {p["id"]: p["name"] for p in platforms_data["platforms"]}
|
||||
|
||||
subcat_by_parent = {}
|
||||
for sub in subcategories:
|
||||
parent = sub.get("parent", "other")
|
||||
subcat_by_parent.setdefault(parent, []).append({
|
||||
"Name": sub["name"],
|
||||
"id": sub["id"]
|
||||
})
|
||||
subcat_by_parent.setdefault(parent, []).append(
|
||||
{"Name": sub["name"], "id": sub["id"]}
|
||||
)
|
||||
|
||||
for key in subcat_by_parent:
|
||||
subcat_by_parent[key].sort(key=lambda x: x["Name"].lower())
|
||||
|
||||
|
||||
apps_by_subcat = {}
|
||||
for app in applications:
|
||||
@@ -77,7 +81,6 @@ def generate_contents(platform="all"):
|
||||
if platform == "all":
|
||||
include = True
|
||||
else:
|
||||
|
||||
app_platforms = [p.lower() for p in app.get("platforms", [])]
|
||||
target = platform.lower()
|
||||
if target in app_platforms:
|
||||
@@ -87,7 +90,7 @@ def generate_contents(platform="all"):
|
||||
include = True
|
||||
if not include:
|
||||
continue
|
||||
|
||||
|
||||
cat_id = app.get("category", "uncategorized")
|
||||
apps_by_subcat.setdefault(cat_id, []).append(app)
|
||||
|
||||
@@ -96,11 +99,13 @@ def generate_contents(platform="all"):
|
||||
|
||||
md_output = ""
|
||||
|
||||
parent_items = [(pid, parent_map.get(pid, pid)) for pid in subcat_by_parent if pid != "other"]
|
||||
parent_items = [
|
||||
(pid, parent_map.get(pid, pid)) for pid in subcat_by_parent if pid != "other"
|
||||
]
|
||||
parent_items.sort(key=lambda x: x[1].lower())
|
||||
if "other" in subcat_by_parent:
|
||||
parent_items.append(("other", "Other"))
|
||||
|
||||
|
||||
for pid, pname in parent_items:
|
||||
md_output += f"# {pname} - [Go to top](#table-of-contents)\n\n"
|
||||
|
||||
@@ -120,22 +125,35 @@ def generate_contents(platform="all"):
|
||||
"""
|
||||
if app.get("tags"):
|
||||
tags += " " + " ".join(app["tags"])
|
||||
"""
|
||||
"""
|
||||
if app.get("tags"):
|
||||
# attribute_tags = " " + " ".join(attribute_map.get(tag, tag) for tag in app.get("tags", []))
|
||||
attribute_tags = " " + " ".join(attribute_map[tag] for tag in app["tags"] if tag in attribute_map)
|
||||
property_tags = " ".join(f"`{property_map[tag]}`" for tag in app["tags"] if tag in property_map)
|
||||
attribute_tags = " " + " ".join(
|
||||
attribute_map[tag]
|
||||
for tag in app["tags"]
|
||||
if tag in attribute_map
|
||||
)
|
||||
property_tags = " ".join(
|
||||
f"`{property_map[tag]}`"
|
||||
for tag in app["tags"]
|
||||
if tag in property_map
|
||||
)
|
||||
|
||||
# app_platforms = " ".join(f"`{p}`" for p in app.get("platforms", []))
|
||||
app_platforms = " ".join(f"`{platform_map.get(p, p)}`" for p in app.get("platforms", []))
|
||||
app_platforms = " ".join(
|
||||
f"`{platform_map.get(p, p)}`" for p in app.get("platforms", [])
|
||||
)
|
||||
stars = app.get("stars")
|
||||
stars_formatted = f"**{format_stars(stars)}**" if stars is not None else ""
|
||||
stars_formatted = (
|
||||
f"**{format_stars(stars)}**" if stars is not None else ""
|
||||
)
|
||||
# repo_path = extract_repo_path(link)
|
||||
# stars_badge = f"" if repo_path else ""
|
||||
md_output += f"| [{name}]({link}){attribute_tags}{property_tags} | {description} | {app_platforms} | {stars_formatted} |\n"
|
||||
md_output += "\n"
|
||||
return md_output
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# For testing, default to 'all' platforms
|
||||
print(generate_contents("all"))
|
||||
|
||||
Reference in New Issue
Block a user