add script to generate per-category lists. auto alphabetizes tables and table contents
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import urllib.parse
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def make_obtainium_link(app):
|
||||
@@ -11,38 +12,59 @@ def make_obtainium_link(app):
|
||||
"name": app["name"],
|
||||
"preferredApkIndex": app.get("preferredApkIndex", 0),
|
||||
"additionalSettings": app.get("additionalSettings", ""),
|
||||
"categories": app.get("categories", []),
|
||||
"overrideSource": app.get("overrideSource", ""),
|
||||
}
|
||||
encoded = urllib.parse.quote(json.dumps(payload), safe="")
|
||||
return f"http://apps.obtainium.imranr.dev/redirect.html?r=obtainium://app/{encoded}"
|
||||
|
||||
|
||||
# ❌
|
||||
def generate_markdown_table(apps):
|
||||
rows = []
|
||||
header = (
|
||||
"| Application Name | Category | Add to Obtainium | Included in export json? |"
|
||||
)
|
||||
divider = (
|
||||
"|------------------|----------|------------------|--------------------------|"
|
||||
)
|
||||
rows.append(header)
|
||||
rows.append(divider)
|
||||
def get_sort_name(app):
|
||||
return app.get("meta", {}).get("nameOverride") or app.get("name", "")
|
||||
|
||||
|
||||
def get_display_name(app):
|
||||
return app.get("meta", {}).get("nameOverride") or app.get("name", "")
|
||||
|
||||
|
||||
def generate_category_tables(apps):
|
||||
# Categorize apps
|
||||
categorized = defaultdict(list)
|
||||
for app in apps:
|
||||
meta = app.get("meta", {})
|
||||
if meta.get("excludeFromTable", False):
|
||||
continue
|
||||
categories = app.get("categories", [])
|
||||
for category in categories:
|
||||
categorized[category].append(app)
|
||||
|
||||
name = meta.get("nameOverride", app.get("name", ""))
|
||||
category = ", ".join(app.get("categories", []))
|
||||
obtainium_link = make_obtainium_link(app)
|
||||
badge_md = f'<a href="{obtainium_link}">Add to Obtainium!</a>'
|
||||
isIncludedInJson = "❌" if meta.get("excludeFromExport") else "✅"
|
||||
rows.append(f"| {name} | {category} | {badge_md} | {isIncludedInJson} |")
|
||||
markdown_sections = ["## Applications"]
|
||||
|
||||
return "\n".join(rows)
|
||||
for category in sorted(categorized.keys()):
|
||||
markdown_sections.append(f"### {category}\n")
|
||||
markdown_sections.append(
|
||||
"| Application Name | Add to Obtainium | Included in export json? |"
|
||||
)
|
||||
markdown_sections.append(
|
||||
"|------------------|------------------|---------------------------|"
|
||||
)
|
||||
|
||||
apps_in_category = sorted(categorized[category], key=get_sort_name)
|
||||
|
||||
for app in apps_in_category:
|
||||
meta = app.get("meta", {})
|
||||
if meta.get("excludeFromTable", False):
|
||||
continue
|
||||
|
||||
display_name = get_display_name(app)
|
||||
obtainium_link = make_obtainium_link(app)
|
||||
badge_md = f'<a href="{obtainium_link}">Add to Obtainium!</a>'
|
||||
include_json = (
|
||||
"❌" if app.get("meta", {}).get("excludeFromExport") else "✅"
|
||||
)
|
||||
|
||||
markdown_sections.append(
|
||||
f"| {display_name} | {badge_md} | {include_json} |"
|
||||
)
|
||||
|
||||
markdown_sections.append("") # blank line between sections
|
||||
|
||||
return "\n".join(markdown_sections)
|
||||
|
||||
|
||||
def main(input_file, output_file):
|
||||
@@ -50,17 +72,17 @@ def main(input_file, output_file):
|
||||
data = json.load(f)
|
||||
|
||||
apps = data.get("apps", [])
|
||||
markdown = generate_markdown_table(apps)
|
||||
markdown = generate_category_tables(apps)
|
||||
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
f.write(markdown)
|
||||
|
||||
print(f"✅ Markdown table written to {output_file}")
|
||||
print(f"✅ Category-based markdown table written to {output_file}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python json_to_markdown.py input.json output.md")
|
||||
print("Usage: python json_to_markdown_by_category.py input.json output.md")
|
||||
sys.exit(1)
|
||||
|
||||
main(sys.argv[1], sys.argv[2])
|
||||
|
||||
Reference in New Issue
Block a user