#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 检查Notion数据库结构 """ import requests import json # Notion API 配置 NOTION_API_KEY = "ntn_c43902219395mirQBetIfYoww1qKCAF14GBRUQeDee29o2" DATABASE_ID = "2fb105ad-7873-81cf-90cc-dad8f1277ded" # 联系人数据库 ID def get_database_info(): """获取数据库信息""" print("=" * 60) print("检查Notion数据库结构") print("=" * 60) print(f"数据库ID: {DATABASE_ID}") print("=" * 60) # Notion API 端点 url = f"https://api.notion.com/v1/databases/{DATABASE_ID}" # 请求头 headers = { "Authorization": f"Bearer {NOTION_API_KEY}", "Content-Type": "application/json", "Notion-Version": "2022-06-28" } try: # 发送请求 response = requests.get(url, headers=headers) if response.status_code == 200: result = response.json() print("\n✅ 数据库信息获取成功!") print("=" * 60) # 打印数据库属性 properties = result.get("properties", {}) print(f"数据库标题: {result.get('title', 'N/A')}") print(f"属性数量: {len(properties)}") print("\n数据库属性:") print("-" * 60) for prop_name, prop_info in properties.items(): prop_type = prop_info.get("type", "N/A") print(f" {prop_name}: {prop_type}") # 如果是选择类型,显示选项 if prop_type in ["select", "multi_select"]: options = prop_info.get(prop_type, {}).get("options", []) if options: print(f" 选项: {[opt['name'] for opt in options]}") print("=" * 60) return properties else: print(f"\n❌ 获取失败") print(f"状态码: {response.status_code}") print(f"错误信息: {response.text}") return None except Exception as e: print(f"\n❌ 发生错误: {e}") return None def main(): """主函数""" print("开始检查Notion数据库...") print() properties = get_database_info() if properties: print("\n💡 提示:") print("请根据上面的属性名称修改添加联系人的脚本") print("确保属性名称完全匹配(包括大小写)") else: print("\n🔧 解决方案:") print("1. 检查Notion API密钥") print("2. 检查数据库ID是否正确") print("3. 检查网络连接") if __name__ == "__main__": main()