# -*- coding: utf-8 -*- """ Created on Wed Jul 23 20:37:12 2025 @author: USER """ from notion_client import Client import csv # --- CONFIG --- NOTION_TOKEN = "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" PAGE_ID = "d95dd2dd7eb14634819dadb16b738d22" TODO_PREFIX = "To do du projet @" notion = Client(auth=NOTION_TOKEN) # --- UTILS --- def get_children(block_id): try: res = notion.blocks.children.list(block_id) return res.get("results", []) except Exception: return [] def extract_text(block): content = block.get(block["type"], {}) for key in ("rich_text", "title"): if isinstance(content.get(key), list): return "".join(t.get("plain_text", "") for t in content[key]) return "" # --- Explorer récursivement la page pour trouver la base dans un toggle --- def find_database_in_page(page_id): for block in get_children(page_id): if block["type"] == "toggle": toggle_title = extract_text(block).strip() print(f"🧱 toggle | {toggle_title} | ID: {block['id']}") children = get_children(block["id"]) for child in children: if child["type"] == "child_database": print(f"📘 Base trouvée dans toggle : ID = {child['id']}") return child["id"] print("❌ Aucune base trouvée dans un toggle.") return None