Files
CookIT/tools/excel-import/convert.py
T
2026-10-28 22:55:09 +01:00

46 lines
1.7 KiB
Python

"""Convert the Wochenspeiseplan workbook into a CookIt Recipe Bundle.
Usage: python convert.py <Wochenspeiseplan.xlsm> [-o out/cookit-rezepte.zip]
"""
from __future__ import annotations
import argparse
import os
import sys
from collections import Counter
from cookit_import.bundle import write_bundle
from cookit_import.recipe import build_recipe, is_recipe_sheet, real_photos, template_photo_hashes
from cookit_import.workbook import read_sheets
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("workbook")
parser.add_argument("-o", "--output", default=os.path.join("out", "cookit-rezepte.zip"))
args = parser.parse_args(argv)
sys.stdout.reconfigure(encoding="utf-8")
print(f"Lese {args.workbook} …")
all_sheets = read_sheets(args.workbook)
placeholders = template_photo_hashes(all_sheets)
sheets = [s for s in all_sheets if is_recipe_sheet(s)]
recipes = [(build_recipe(s), real_photos(s, placeholders)) for s in sheets]
os.makedirs(os.path.dirname(args.output) or ".", exist_ok=True)
write_bundle(args.output, recipes)
flagged = [r for r, _ in recipes if r["reviewReasons"]]
reasons = Counter(reason.split(":")[0] for r in flagged for reason in r["reviewReasons"])
print(f"{len(recipes)} Rezepte, {sum(len(r['photos']) for r, _ in recipes)} Fotos")
print(f"{len(flagged)} Rezepte mit Prüfhinweis:")
for reason, count in reasons.most_common():
print(f" {count:4d} {reason}")
print(f"Geschrieben: {args.output} ({os.path.getsize(args.output) / 1_000_000:.1f} MB)")
return 0
if __name__ == "__main__":
raise SystemExit(main())