167 lines
7.5 KiB
Python
167 lines
7.5 KiB
Python
# import_product.py
|
|
import requests
|
|
import json
|
|
import re
|
|
|
|
# --- Configuration ---
|
|
NOTION_TOKEN = "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" # This will be replaced by the user's actual token.
|
|
NOTION_VERSION = "2022-06-28"
|
|
NOTION_API_BASE_URL = "https://api.notion.com/v1"
|
|
|
|
HEADERS = {
|
|
"Authorization": f"Bearer {NOTION_TOKEN}",
|
|
"Notion-Version": NOTION_VERSION,
|
|
"Content-Type": "application/json",
|
|
}
|
|
|
|
# --- Database IDs (from Notion_Dashboard.md) ---
|
|
DB_IDS = {
|
|
"Product Master": "2e288f42-8544-81d8-96f5-c231f84f719a",
|
|
"Sector & Persona Master": "2e288f42-8544-8113-b878-ec99c8a02a6b",
|
|
"Messaging Matrix": "2e288f42-8544-81b0-83d4-c16623cc32d1",
|
|
}
|
|
|
|
# --- Helper Functions ---
|
|
|
|
def create_notion_page(database_id, properties):
|
|
"""Creates a new page in a Notion database."""
|
|
url = f"{NOTION_API_BASE_URL}/pages"
|
|
payload = {
|
|
"parent": {"database_id": database_id},
|
|
"properties": properties,
|
|
}
|
|
try:
|
|
response = requests.post(url, headers=HEADERS, json=payload)
|
|
response.raise_for_status()
|
|
print(f"Successfully created page in DB {database_id}.")
|
|
return response.json()
|
|
except requests.exceptions.HTTPError as e:
|
|
print(f"HTTP Error creating page in DB {database_id}: {e}")
|
|
print(f"Response content: {response.text}")
|
|
return None
|
|
except Exception as e:
|
|
print(f"An unexpected error occurred while creating a page: {e}")
|
|
return None
|
|
|
|
def format_rich_text(text):
|
|
"""Formats a string into Notion's rich text structure."""
|
|
return {"rich_text": [{"type": "text", "text": {"content": text}}]}
|
|
|
|
def format_title(text):
|
|
"""Formats a string into Notion's title structure."""
|
|
return {"title": [{"type": "text", "text": {"content": text}}]}
|
|
|
|
def format_relation(page_ids):
|
|
"""Formats a list of page IDs into Notion's relation structure."""
|
|
if not isinstance(page_ids, list):
|
|
page_ids = [page_ids] # Ensure it's a list
|
|
return {"relation": [{"id": page_id} for page_id in page_ids]}
|
|
|
|
def extract_section(content, title):
|
|
"""Extracts a section from markdown content based on a ## title."""
|
|
pattern = re.compile(rf"## {re.escape(title)}\n(.*?)(?=\n## |\Z)", re.S)
|
|
match = pattern.search(content)
|
|
return match.group(1).strip() if match else ""
|
|
|
|
# --- Main Import Logic ---
|
|
|
|
def main():
|
|
if NOTION_TOKEN == "YOUR_NOTION_TOKEN":
|
|
print("ERROR: Please replace 'YOUR_NOTION_TOKEN' in the script with your actual Notion token.")
|
|
return
|
|
|
|
# 1. Read the markdown file
|
|
try:
|
|
with open("Puma_m20_2026-01-08.md", "r", encoding="utf-8") as f:
|
|
md_content = f.read()
|
|
except FileNotFoundError:
|
|
print("ERROR: 'Puma_m20_2026-01-08.md' not found. Please make sure the file is in the same directory.")
|
|
return
|
|
|
|
# --- Phase 1: Create Product in Product Master ---
|
|
print("--- Phase 1: Creating Product ---")
|
|
product_analysis = extract_section(md_content, "2. Product Analysis")
|
|
key_features = re.search(r"\*\*Key Features:\*\*(.*?)\*\*Constraints:\*\*", product_analysis, re.S).group(1).strip()
|
|
constraints = re.search(r"\*\*Constraints:\*\*(.*)", product_analysis, re.S).group(1).strip()
|
|
|
|
product_properties = {
|
|
"Name": format_title("Puma M20"),
|
|
"Beschreibung": format_rich_text("Ein geländegängiger, wetterfester Roboter, der für anspruchsvolle Umgebungen konzipiert wurde."),
|
|
"Spezifikationen": format_rich_text(f"Key Features:\n{key_features}\n\nConstraints:\n{constraints}"),
|
|
"Layer": {"multi_select": [{"name": "Security"}, {"name": "Service"}]}
|
|
}
|
|
|
|
product_page = create_notion_page(DB_IDS["Product Master"], product_properties)
|
|
if not product_page:
|
|
print("Failed to create product page. Aborting.")
|
|
return
|
|
product_page_id = product_page["id"]
|
|
print(f"Created Product 'Puma M20' with ID: {product_page_id}")
|
|
|
|
|
|
# --- Phase 2: Create Sectors in Sector & Persona Master ---
|
|
print("\n--- Phase 2: Creating Sectors ---")
|
|
sector_pages = {}
|
|
sectors = {
|
|
"Chemieparks/Petrochemische Anlagen": {
|
|
"definition": "Anlagen dieser Art haben ausgedehnte Gelände, komplexe Infrastruktur und hohe Sicherheitsanforderungen...",
|
|
"pains": "Umfangreiche Gelände erfordern ständige Sicherheits- und Inspektionsrundgänge, oft unter gefährlichen Bedingungen. Personalmangel und hohe Kosten für manuelle Inspektionen.",
|
|
"personas": ["Head of Security", "Werkschutzleiter", "Geschäftsführer/Vorstand", "Leiter Instandhaltung / Betriebsleiter"]
|
|
},
|
|
"Energieversorgungsunternehmen (z.B. Windparks, Solarparks)": {
|
|
"definition": "Diese Anlagen erstrecken sich oft über große, schwer zugängliche Gebiete...",
|
|
"pains": "Weitläufige Anlagen in oft unwegsamem Gelände. Schwierige und teure Inspektion von Solarmodulen oder Windkraftanlagen. Anfälligkeit für Vandalismus und Diebstahl.",
|
|
"personas": ["Head of Security", "Geschäftsführer/Vorstand", "Leiter Instandhaltung / Betriebsleiter"]
|
|
},
|
|
"Logistikzentren/Großflächenlager": {
|
|
"definition": "Große Lagerflächen und komplexe Logistikprozesse erfordern eine ständige Überwachung und Inspektion.",
|
|
"pains": "Hohe Anforderungen an Sicherheit und Ordnung in großen Lagerhallen... Ineffiziente manuelle Reinigung großer Flächen. Gefahr von Unfällen...",
|
|
"personas": ["Leiter Instandhaltung / Betriebsleiter", "Geschäftsführer/Vorstand", "Head of Security"]
|
|
}
|
|
|
|
}
|
|
|
|
for name, data in sectors.items():
|
|
sector_properties = {
|
|
"Name": format_title(name),
|
|
"RoboPlanet-Definition": format_rich_text(data["definition"]),
|
|
"Pains": format_rich_text(data["pains"]),
|
|
"Personas": {"multi_select": [{"name": p} for p in data["personas"]]}
|
|
}
|
|
sector_page = create_notion_page(DB_IDS["Sector & Persona Master"], sector_properties)
|
|
if sector_page:
|
|
sector_pages[name] = sector_page["id"]
|
|
print(f"Created Sector '{name}' with ID: {sector_page['id']}")
|
|
else:
|
|
print(f"Failed to create sector '{name}'.")
|
|
|
|
|
|
# --- Phase 3: Create Messaging Elements ---
|
|
print("\n--- Phase 3: Creating Messaging Elements (Battlecards) ---")
|
|
battlecards_content = extract_section(md_content, "Kill-Critique Battlecards")
|
|
battlecards = re.findall(r"### Persona: (.*?)\n> \*\*Objection:\*\* \"(.*?)\"\n\n\*\*Response:\*\* (.*?)(?=\n\n---|\Z)", battlecards_content, re.S)
|
|
|
|
for persona, objection, response in battlecards:
|
|
# Determine which sector this battlecard applies to
|
|
current_sector_id = None
|
|
if "Chemiepark" in response or "Wackler Security" in response:
|
|
current_sector_id = sector_pages.get("Chemieparks/Petrochemische Anlagen")
|
|
if "Logistik" in response or "Reinigung" in response:
|
|
current_sector_id = sector_pages.get("Logistikzentren/Großflächenlager")
|
|
|
|
message_properties = {
|
|
"Name": format_title(f"Objection: {objection}"),
|
|
"Satz 1": format_rich_text(f"Persona: {persona.strip()}\nObjection: {objection}"),
|
|
"Satz 2": format_rich_text(response.strip()),
|
|
"Product Master": format_relation(product_page_id),
|
|
}
|
|
if current_sector_id:
|
|
message_properties["Sector Master"] = format_relation(current_sector_id)
|
|
|
|
create_notion_page(DB_IDS["Messaging Matrix"], message_properties)
|
|
|
|
print("\nImport process complete.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|