Initial commit: What To Cook (WTC) v4.4 - Digitales Kochbuch, Wochenmenueplan & Buchdruck

This commit is contained in:
2026-10-14 20:24:37 +02:00
commit c01d2d7639
171 changed files with 14073 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import os
from pypdf import PdfReader
SRC = '/home/maxi/Projekt/wtc.waiswuaschd.de/data/import_2026'
IMG_OUT = '/home/maxi/Projekt/wtc.waiswuaschd.de/app/static/uploads/recipes'
for f in sorted(os.listdir(SRC)):
if not f.lower().endswith('.pdf'):
continue
path = os.path.join(SRC, f)
base = os.path.splitext(f)[0]
safe_name = "".join(c for c in base if c.isalnum() or c in (' ', '_', '-')).strip().replace(' ', '_').lower()
try:
reader = PdfReader(path)
img_idx = 0
best_img = None
best_size = 0
best_ext = '.jpg'
for page in reader.pages:
for img in page.images:
data = img.data
if len(data) > 20000 and len(data) > best_size: # > 20KB
best_size = len(data)
best_img = data
best_ext = os.path.splitext(img.name)[1].lower() or '.jpg'
if best_img:
target_file = f"{safe_name}{best_ext}"
target_path = os.path.join(IMG_OUT, target_file)
with open(target_path, 'wb') as out_f:
out_f.write(best_img)
print(f"Extracted PDF image for {f}: {target_file} ({best_size} bytes)")
except Exception as e:
print(f"Error reading PDF {f}: {e}")