]> piware.de Git - bin.git/commitdiff
recipekeeper-split: Start from zip file
authorMartin Pitt <martin@piware.de>
Sun, 1 Jun 2025 14:48:25 +0000 (16:48 +0200)
committerMartin Pitt <martin@piware.de>
Sun, 1 Jun 2025 14:48:25 +0000 (16:48 +0200)
recipekeeper-split

index c43770a4d3325da0329893a96c6435de2a5d51b3..2017862b1b871a9afc574d55472f9d4d2af61469 100755 (executable)
@@ -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 <meta ...> tags: make them self-closing
@@ -64,6 +76,9 @@ for recipe in recipes:
         ET.tostring(recipe, encoding="unicode") + '\n' +
         '</body>\n</html>'
     )
-    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"))