[2ff88f42] multiplikation vorbereitet
multiplikation vorbereitet
This commit is contained in:
@@ -7,7 +7,7 @@ import logging
|
||||
# /app/backend/scripts/sync.py -> /app
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
from backend.database import SessionLocal, Industry, RoboticsCategory, init_db
|
||||
from backend.database import SessionLocal, Industry, RoboticsCategory, Persona, init_db
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Try loading from .env in root if exists
|
||||
@@ -76,6 +76,21 @@ def extract_number(prop):
|
||||
if not prop or "number" not in prop: return None
|
||||
return prop["number"]
|
||||
|
||||
def extract_rich_text_to_list(prop):
|
||||
if not prop or "rich_text" not in prop: return []
|
||||
full_text = "".join([t.get("plain_text", "") for t in prop.get("rich_text", [])])
|
||||
lines = full_text.split('\n')
|
||||
cleaned_lines = []
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line: continue
|
||||
if line.startswith("- "):
|
||||
line = line[2:]
|
||||
elif line.startswith("• "):
|
||||
line = line[2:]
|
||||
cleaned_lines.append(line)
|
||||
return cleaned_lines
|
||||
|
||||
def sync():
|
||||
logger.info("--- Starting Enhanced Sync ---")
|
||||
|
||||
@@ -83,6 +98,48 @@ def sync():
|
||||
init_db()
|
||||
session = SessionLocal()
|
||||
|
||||
# --- 4. Sync Personas (NEW) ---
|
||||
# Sector & Persona Master ID
|
||||
PERSONAS_DB_ID = "2e288f42-8544-8113-b878-ec99c8a02a6b"
|
||||
VALID_ARCHETYPES = {
|
||||
"Wirtschaftlicher Entscheider",
|
||||
"Operativer Entscheider",
|
||||
"Infrastruktur-Verantwortlicher",
|
||||
"Innovations-Treiber"
|
||||
}
|
||||
|
||||
if PERSONAS_DB_ID:
|
||||
logger.info(f"Syncing Personas from {PERSONAS_DB_ID}...")
|
||||
pages = query_all(PERSONAS_DB_ID)
|
||||
p_count = 0
|
||||
|
||||
# We assume Personas are cumulative, so we don't delete all first (safer for IDs)
|
||||
# But we could if we wanted a clean slate. Upsert is better.
|
||||
|
||||
for page in pages:
|
||||
props = page["properties"]
|
||||
name = extract_title(props.get("Name"))
|
||||
|
||||
if name not in VALID_ARCHETYPES:
|
||||
continue
|
||||
|
||||
import json
|
||||
pains_list = extract_rich_text_to_list(props.get("Pains"))
|
||||
gains_list = extract_rich_text_to_list(props.get("Gains"))
|
||||
|
||||
persona = session.query(Persona).filter(Persona.name == name).first()
|
||||
if not persona:
|
||||
persona = Persona(name=name)
|
||||
session.add(persona)
|
||||
|
||||
persona.pains = json.dumps(pains_list, ensure_ascii=False)
|
||||
persona.gains = json.dumps(gains_list, ensure_ascii=False)
|
||||
|
||||
p_count += 1
|
||||
|
||||
session.commit()
|
||||
logger.info(f"✅ Synced {p_count} Personas.")
|
||||
|
||||
# 2. Sync Categories (Products)
|
||||
cat_db_id = find_db_id("Product Categories") or find_db_id("Products")
|
||||
if cat_db_id:
|
||||
|
||||
Reference in New Issue
Block a user