#!/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):
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
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"))