import json import os import requests import sys # Configuration JSON_FILE = 'analysis_robo-planet.de-2.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" def load_json_data(filepath): with open(filepath, 'r') as f: return json.load(f) def load_notion_token(filepath): with open(filepath, 'r') as f: return f.read().strip() def create_database(token, parent_id, title, properties): url = "https://api.notion.com/v1/databases" headers = {"Authorization": f"Bearer {token}", "Notion-Version": "2022-06-28", "Content-Type": "application/json"} 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}") sys.exit(1) return r.json()['id'] def create_page(token, db_id, properties): url = "https://api.notion.com/v1/pages" 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) return r.json().get('id') def main(): token = load_notion_token(TOKEN_FILE) data = load_json_data(JSON_FILE) print("🚀 Level 4 Import starting...") hub_id = create_database(token, PARENT_PAGE_ID, DB_TITLE_HUB, { "Name": {"title": {}}, "Website": {"url": {}}, "Target Industries": {"multi_select": {}} }) lm_id = create_database(token, PARENT_PAGE_ID, DB_TITLE_LANDMINES, { "Question": {"title": {}}, "Topic": {"select": {}}, "Related Competitor": {"relation": {"database_id": hub_id, "dual_property": {"synced_property_name": "Landmines"}}} }) prod_id = create_database(token, PARENT_PAGE_ID, DB_TITLE_PRODUCTS, { "Product": {"title": {}}, "Category": {"select": {}}, "Related Competitor": {"relation": {"database_id": hub_id, "dual_property": {"synced_property_name": "Products"}}} }) comp_map = {} for analysis in data.get('analyses', []): c = analysis['competitor'] name = c['name'] 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', [])]} } pid = create_page(token, hub_id, props) if pid: comp_map[name] = pid print(f" - Created: {name}") for prod in analysis.get('portfolio', []): p_props = { "Product": {"title": [{"text": {"content": prod['product'][:100]}}]}, "Category": {"select": {"name": prod.get('purpose', 'Other')[:100]}}, "Related Competitor": {"relation": [{"id": pid}]} } create_page(token, prod_id, p_props) for card in data.get('battlecards', []): cid = comp_map.get(card['competitor_name']) if not cid: continue for q in card.get('landmine_questions', []): 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}]} }) print("✅ DONE") if __name__ == "__main__": main()