Initial commit: What To Cook (WTC) v4.4 - Digitales Kochbuch, Wochenmenueplan & Buchdruck
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
import glob
|
||||
from pypdf import PdfReader
|
||||
from docx import Document
|
||||
from pptx import Presentation
|
||||
|
||||
DIR = '/home/maxi/Projekt/wtc.waiswuaschd.de/data/import_2026'
|
||||
files = sorted(os.listdir(DIR))
|
||||
|
||||
for f in files:
|
||||
path = os.path.join(DIR, f)
|
||||
ext = os.path.splitext(f)[1].lower()
|
||||
text = ""
|
||||
try:
|
||||
if ext == '.pdf':
|
||||
reader = PdfReader(path)
|
||||
for page in reader.pages:
|
||||
text += (page.extract_text() or "") + "\n"
|
||||
elif ext == '.docx':
|
||||
doc = Document(path)
|
||||
for p in doc.paragraphs:
|
||||
if p.text.strip():
|
||||
text += p.text.strip() + "\n"
|
||||
for t in doc.tables:
|
||||
for row in t.rows:
|
||||
row_txt = [c.text.strip() for c in row.cells if c.text.strip()]
|
||||
if row_txt:
|
||||
text += " | ".join(row_txt) + "\n"
|
||||
elif ext == '.pptx':
|
||||
prs = Presentation(path)
|
||||
for slide in prs.slides:
|
||||
for shape in slide.shapes:
|
||||
if shape.has_text_frame:
|
||||
for paragraph in shape.text_frame.paragraphs:
|
||||
if paragraph.text.strip():
|
||||
text += paragraph.text.strip() + "\n"
|
||||
elif ext in ['.jpg', '.png', '.jpeg']:
|
||||
text = f"[IMAGE FILE: {f}]"
|
||||
else:
|
||||
text = f"[UNKNOWN EXT: {ext}]"
|
||||
except Exception as e:
|
||||
text = f"[ERROR: {e}]"
|
||||
|
||||
first_lines = [l.strip() for l in text.split('\n') if l.strip()][:5]
|
||||
print(f"=== {f} ({len(text)} chars) ===")
|
||||
print("\n".join(first_lines[:4]))
|
||||
print()
|
||||
Reference in New Issue
Block a user