feat(ca): Add analysis loading feature and update documentation to v5-Stable

This commit is contained in:
2026-01-12 15:44:26 +00:00
parent 70e689384e
commit 5283f8a84b
5 changed files with 117 additions and 14 deletions

View File

@@ -4,15 +4,15 @@ import requests
import sys
# Configuration
JSON_FILE = 'analysis_robo-planet.de-2.json'
JSON_FILE = 'analysis_robo-planet.de-4.json'
TOKEN_FILE = 'notion_token.txt'
PARENT_PAGE_ID = "2e088f42-8544-8024-8289-deb383da3818"
# Database Titles
DB_TITLE_HUB = "📦 Competitive Radar (Companies) v5"
DB_TITLE_LANDMINES = "💣 Competitive Radar (Landmines) v5"
DB_TITLE_REFS = "🏆 Competitive Radar (References) v5"
DB_TITLE_PRODUCTS = "🤖 Competitive Radar (Products) v5"
DB_TITLE_HUB = "📦 Competitive Radar (Companies) v6"
DB_TITLE_LANDMINES = "💣 Competitive Radar (Landmines) v6"
DB_TITLE_REFS = "🏆 Competitive Radar (References) v6"
DB_TITLE_PRODUCTS = "🤖 Competitive Radar (Products) v6"
def load_json_data(filepath):
with open(filepath, 'r') as f:
@@ -28,7 +28,7 @@ def create_database(token, parent_id, title, properties):
payload = {"parent": {"type": "page_id", "page_id": parent_id}, "title": [{"type": "text", "text": {"content": title}}], "properties": properties}
r = requests.post(url, headers=headers, json=payload)
if r.status_code != 200:
print(f"Error {title}: {r.text}")
print(f"Error creating DB '{title}': {r.text}")
sys.exit(1)
return r.json()['id']
@@ -37,14 +37,17 @@ def create_page(token, db_id, properties):
headers = {"Authorization": f"Bearer {token}", "Notion-Version": "2022-06-28", "Content-Type": "application/json"}
payload = {"parent": {"database_id": db_id}, "properties": properties}
r = requests.post(url, headers=headers, json=payload)
if r.status_code != 200:
print(f"Error creating page: {r.text}")
return r.json().get('id')
def main():
token = load_notion_token(TOKEN_FILE)
data = load_json_data(JSON_FILE)
print("🚀 Level 4 Import starting...")
print("🚀 Level 5 Import starting (v6 Databases)...")
# 1. Create Databases
hub_id = create_database(token, PARENT_PAGE_ID, DB_TITLE_HUB, {
"Name": {"title": {}},
"Website": {"url": {}},
@@ -60,43 +63,72 @@ def main():
prod_id = create_database(token, PARENT_PAGE_ID, DB_TITLE_PRODUCTS, {
"Product": {"title": {}},
"Category": {"select": {}},
"Purpose": {"rich_text": {}},
"Related Competitor": {"relation": {"database_id": hub_id, "dual_property": {"synced_property_name": "Products"}}}
})
ref_id = create_database(token, PARENT_PAGE_ID, DB_TITLE_REFS, {
"Customer": {"title": {}},
"Industry": {"select": {}},
"Quote": {"rich_text": {}},
"Related Competitor": {"relation": {"database_id": hub_id, "dual_property": {"synced_property_name": "References"}}}
})
# 2. Import Companies & Products
comp_map = {}
for analysis in data.get('analyses', []):
c = analysis['competitor']
name = c['name']
# v5: 'target_industries' is at root level of analysis object
industries = analysis.get('target_industries', [])
props = {
"Name": {"title": [{"text": {"content": name}}]},
"Website": {"url": c['url'] or "https://google.com"},
"Target Industries": {"multi_select": [{"name": i[:100]} for i in analysis.get('target_industries', [])]}
"Target Industries": {"multi_select": [{"name": i[:100].replace(',', '')} for i in industries if i]}
}
pid = create_page(token, hub_id, props)
if pid:
comp_map[name] = pid
print(f" - Created: {name}")
print(f" - Created Company: {name}")
for prod in analysis.get('portfolio', []):
p_props = {
"Product": {"title": [{"text": {"content": prod['product'][:100]}}]},
"Category": {"select": {"name": prod.get('purpose', 'Other')[:100]}},
"Category": {"select": {"name": prod.get('category', 'Other')[:100]}},
"Purpose": {"rich_text": [{"text": {"content": prod.get('purpose', '')[:2000]}}]},
"Related Competitor": {"relation": [{"id": pid}]}
}
create_page(token, prod_id, p_props)
# 3. Import Battlecards (Landmines)
for card in data.get('battlecards', []):
cid = comp_map.get(card['competitor_name'])
if not cid: continue
for q in card.get('landmine_questions', []):
# Handle both string and object formats from LLM
text = q['text'] if isinstance(q, dict) else q
cat = q.get('category', 'General') if isinstance(q, dict) else 'General'
create_page(token, lm_id, {
"Question": {"title": [{"text": {"content": text[:100]}}]},
"Topic": {"select": {"name": cat}},
"Related Competitor": {"relation": [{"id": cid}]}
})
# 4. Import References
for ref_analysis in data.get('reference_analysis', []):
cid = comp_map.get(ref_analysis['competitor_name'])
if not cid: continue
for ref in ref_analysis.get('references', []):
create_page(token, ref_id, {
"Customer": {"title": [{"text": {"content": ref['name'][:100]}}]},
"Industry": {"select": {"name": ref.get('industry', 'Unknown')[:100].replace(',', '')}},
"Quote": {"rich_text": [{"text": {"content": ref.get('testimonial_snippet', '')[:2000]}}]},
"Related Competitor": {"relation": [{"id": cid}]}
})
print("✅ DONE")
if __name__ == "__main__":