37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import os
|
|
import sys
|
|
import re
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
from app.database import get_connection
|
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
conn = get_connection()
|
|
cur = conn.cursor()
|
|
cur.execute("SELECT id, title, instructions FROM recipes ORDER BY id")
|
|
recipes = cur.fetchall()
|
|
|
|
def clean_instructions(text: str) -> str:
|
|
cleaned_lines = []
|
|
for line in text.split("\n"):
|
|
line_s = line.strip()
|
|
if not line_s:
|
|
continue
|
|
cleaned = re.sub(r'^(?:Schritt\s*)?\d+[\.\)\:\-]?\s*', '', line_s, flags=re.IGNORECASE)
|
|
cleaned_lines.append(cleaned)
|
|
return "\n".join(cleaned_lines)
|
|
|
|
print(f"Total recipes to preview: {len(recipes)}")
|
|
for r in recipes[:10]:
|
|
lines_before = [l.strip() for l in r['instructions'].split('\n') if l.strip()]
|
|
lines_after = [l.strip() for l in clean_instructions(r['instructions']).split('\n') if l.strip()]
|
|
print(f"\n=== ID {r['id']}: {r['title']} ===")
|
|
for b, a in zip(lines_before[:2], lines_after[:2]):
|
|
print(f" VORHER: {b[:65]}")
|
|
print(f" NACHHER: {a[:65]}")
|
|
|
|
conn.close()
|