add DS file support
This commit is contained in:
@@ -30,6 +30,25 @@ def get_application_url(app):
|
||||
return app.get("meta", {}).get("urlOverride") or app.get("url", "")
|
||||
|
||||
|
||||
def should_include_app(app, variant):
|
||||
"""Determine if an app should be included based on variant and meta fields."""
|
||||
meta = app.get("meta", {})
|
||||
|
||||
# HIGHEST PRIORITY: Global exclusion overrides everything
|
||||
if meta.get("excludeFromExport", False):
|
||||
return False
|
||||
|
||||
# SECOND PRIORITY: Variant-specific inclusion/exclusion
|
||||
if variant == "standard":
|
||||
# Default: include in standard
|
||||
return meta.get("includeInStandard", True)
|
||||
elif variant == "dual-screen":
|
||||
# Default: include in dual screen
|
||||
return meta.get("includeInDualScreen", True)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def generate_category_tables(apps):
|
||||
# Categorize apps
|
||||
categorized = defaultdict(list)
|
||||
@@ -43,10 +62,10 @@ def generate_category_tables(apps):
|
||||
for category in sorted(categorized.keys()):
|
||||
markdown_sections.append(f"### {category}\n")
|
||||
markdown_sections.append(
|
||||
"| Application Name | Add to Obtainium | Included in export json? |"
|
||||
"| Application Name | Add to Obtainium | Included in export json? | Included in DS json? |"
|
||||
)
|
||||
markdown_sections.append(
|
||||
"|------------------|------------------|---------------------------|"
|
||||
"|------------------|------------------|---------------------------|----------------------|"
|
||||
)
|
||||
|
||||
apps_in_category = sorted(categorized[category], key=get_display_name)
|
||||
@@ -61,12 +80,13 @@ def generate_category_tables(apps):
|
||||
)
|
||||
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 "✅"
|
||||
include_standard = "✅" if should_include_app(app, "standard") else "❌"
|
||||
include_dual_screen = (
|
||||
"✅" if should_include_app(app, "dual-screen") else "❌"
|
||||
)
|
||||
|
||||
markdown_sections.append(
|
||||
f"| {display_name} | {badge_md} | {include_json} |"
|
||||
f"| {display_name} | {badge_md} | {include_standard} | {include_dual_screen} |"
|
||||
)
|
||||
|
||||
markdown_sections.append("") # blank line between sections
|
||||
|
||||
@@ -1,36 +1,69 @@
|
||||
import json
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
|
||||
def minify_json(input_file, output_file):
|
||||
def should_include_app(app, variant):
|
||||
"""Determine if an app should be included based on variant and meta fields."""
|
||||
meta = app.get("meta", {})
|
||||
|
||||
# HIGHEST PRIORITY: Global exclusion overrides everything
|
||||
if meta.get("excludeFromExport", False):
|
||||
return False
|
||||
|
||||
# SECOND PRIORITY: Variant-specific inclusion/exclusion
|
||||
if variant == "standard":
|
||||
# Default: include in standard
|
||||
return meta.get("includeInStandard", True)
|
||||
elif variant == "dual-screen":
|
||||
# Default: include in dual screen
|
||||
return meta.get("includeInDualScreen", True)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def minify_json(input_file, output_file, variant="standard"):
|
||||
try:
|
||||
# Read JSON data from input file
|
||||
with open(input_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Filter out apps with meta.exclude_from_json = true
|
||||
# Filter apps based on variant
|
||||
if "apps" in data:
|
||||
filtered_apps = []
|
||||
for app in data["apps"]:
|
||||
meta = app.get("meta", {})
|
||||
if not meta.get("excludeFromExport", False):
|
||||
app.pop("meta", None) # Exclude the 'meta' key from the export json
|
||||
filtered_apps.append(app)
|
||||
if should_include_app(app, variant):
|
||||
# Remove meta key from export
|
||||
app_copy = app.copy()
|
||||
app_copy.pop("meta", None)
|
||||
filtered_apps.append(app_copy)
|
||||
data["apps"] = filtered_apps
|
||||
|
||||
# Minify JSON and write to output file
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, separators=(",", ":"), ensure_ascii=False)
|
||||
|
||||
variant_label = f" ({variant})" if variant != "standard" else ""
|
||||
print(
|
||||
f"Minified JSON saved to {output_file} ({len(data.get('apps', []))} apps included)"
|
||||
f"Minified JSON{variant_label} saved to {output_file} ({len(data.get('apps', []))} apps included)"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python minify_json.py input.json output.json")
|
||||
else:
|
||||
minify_json(sys.argv[1], sys.argv[2])
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Minify and filter Obtainium JSON based on variant"
|
||||
)
|
||||
parser.add_argument("input", help="Input JSON file")
|
||||
parser.add_argument("output", help="Output JSON file")
|
||||
parser.add_argument(
|
||||
"--variant",
|
||||
choices=["standard", "dual-screen"],
|
||||
default="standard",
|
||||
help="Variant to build (default: standard)",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
minify_json(args.input, args.output, args.variant)
|
||||
|
||||
Reference in New Issue
Block a user