From d1d4cca212d639f5d4211601a1671986aca6796b Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 1 Jun 2025 16:48:25 +0200 Subject: [PATCH] recipekeeper-split: Start from zip file --- recipekeeper-split | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/recipekeeper-split b/recipekeeper-split index c43770a..2017862 100755 --- a/recipekeeper-split +++ b/recipekeeper-split @@ -1,9 +1,21 @@ #!/usr/bin/python3 -import re import html +import os +import re +import shutil +import sys import xml.etree.ElementTree as ET +import zipfile + +(recipe_zip, destdir) = sys.argv[1:] -input_file = "recipes.html" +# init destdir +if os.path.exists(destdir): + shutil.rmtree(destdir) +os.makedirs(destdir) + +with zipfile.ZipFile(recipe_zip, 'r') as archive: + archive.extractall(path=destdir) def safe_filename(name): @@ -11,7 +23,7 @@ def safe_filename(name): return name[:40] -with open(input_file, "r") as f: +with open(os.path.join(destdir, "recipes.html"), "r") as f: content = f.read() # 1. Fix tags: make them self-closing @@ -64,6 +76,9 @@ for recipe in recipes: ET.tostring(recipe, encoding="unicode") + '\n' + '\n' ) - with open(filename, "w", encoding="utf-8") as out: + with open(os.path.join(destdir, filename), "w", encoding="utf-8") as out: out.write(out_html) + print(f"Wrote: {filename}") + +os.remove(os.path.join(destdir, "recipes.html")) -- 2.47.2