feat: Enhanced CE schema and Notion sync (Pains/Gains)
This commit is contained in:
93
scripts/generate_ce_hooks.py
Normal file
93
scripts/generate_ce_hooks.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import sqlite3
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load ENV for Gemini API
|
||||
load_dotenv(dotenv_path="/home/node/clawd/.env", override=True)
|
||||
|
||||
class LeadHookService:
|
||||
def __init__(self, db_path):
|
||||
self.db_path = db_path
|
||||
self.api_key = os.getenv("GEMINI_API_KEY")
|
||||
|
||||
def _get_company_data(self, company_id):
|
||||
conn = sqlite3.connect(self.db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Get company and metrics
|
||||
cursor.execute("SELECT * FROM companies WHERE id = ?", (company_id,))
|
||||
company = cursor.fetchone()
|
||||
|
||||
if not company:
|
||||
return None
|
||||
|
||||
data = dict(company)
|
||||
conn.close()
|
||||
return data
|
||||
|
||||
def build_combined_context(self, company_data):
|
||||
# Build the 'combined' string from CE facts
|
||||
parts = []
|
||||
parts.append(f"Name: {company_data.get('name')}")
|
||||
parts.append(f"Branche: {company_data.get('industry_ai')}")
|
||||
|
||||
if company_data.get('calculated_metric_value'):
|
||||
parts.append(f"Metrik: {company_data.get('calculated_metric_value')} {company_data.get('calculated_metric_unit')}")
|
||||
|
||||
# Add a hint about the core business from status/city
|
||||
parts.append(f"Standort: {company_data.get('city')}")
|
||||
|
||||
return " | ".join(parts)
|
||||
|
||||
def generate_hook(self, company_id):
|
||||
company_data = self._get_company_data(company_id)
|
||||
if not company_data:
|
||||
return "Company not found."
|
||||
|
||||
combined = self.build_combined_context(company_data)
|
||||
display_name = company_data.get('name').split(' ')[0] # Simple Kurzname logic
|
||||
|
||||
prompt = f"""
|
||||
Du bist ein exzellenter B2B-Stratege und Texter.
|
||||
Deine Aufgabe ist es, einen hochpersonalisierten, scharfsinnigen und wertschätzenden Einleitungssatz für eine E-Mail zu formulieren.
|
||||
|
||||
--- Unternehmenskontext ---
|
||||
Kurzname: {display_name}
|
||||
Beschreibung: {combined}
|
||||
|
||||
--- Stilvorgaben ---
|
||||
1. Analysiere das Kerngeschäft: Was ist die zentrale physische Herausforderung (z.B. Sauberkeit in Nassbereichen, Logistik-Effizienz, Objektschutz)?
|
||||
2. KEINE ZAHLEN: Erwähne niemals konkrete Zahlen (Besucherzahlen, m², Anzahl Pools). Nutze stattdessen qualitative Begriffe wie "weitläufig", "hochfrequent", "komplex" oder "marktführend".
|
||||
3. Identifiziere den Hebel: Was ist der Erfolgsfaktor (z.B. Gäste-Zufriedenheit, Prozessstabilität, Sicherheit)?
|
||||
4. Formuliere den Satz (20-35 Wörter): Elegant, aktiv, KEINE Floskeln.
|
||||
5. WICHTIG: Formuliere als positive Beobachtung über eine Kernkompetenz.
|
||||
|
||||
Deine Ausgabe: NUR der finale Satz.
|
||||
"""
|
||||
|
||||
# Call Gemini (Simplified for POC)
|
||||
headers = {"Content-Type": "application/json"}
|
||||
payload = {
|
||||
"contents": [{"parts": [{"text": prompt}]}]
|
||||
}
|
||||
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key={self.api_key}"
|
||||
|
||||
resp = requests.post(url, headers=headers, json=payload)
|
||||
result = resp.json()
|
||||
|
||||
try:
|
||||
hook_text = result['candidates'][0]['content']['parts'][0]['text'].strip()
|
||||
return hook_text
|
||||
except:
|
||||
return f"Error generating hook: {result}"
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Test with CE-ID 1 (Therme Erding)
|
||||
db = "/home/node/clawd/repos/brancheneinstufung2/company_explorer_local.db"
|
||||
service = LeadHookService(db)
|
||||
print(f"--- Testing LeadHookService for ID 1 ---")
|
||||
hook = service.generate_hook(1)
|
||||
print(f"GENERATED HOOK:\n{hook}")
|
||||
Reference in New Issue
Block a user