Files
server-configs/add-self-contact.py
2026-02-13 22:24:27 +08:00

128 lines
3.4 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
添加自己到Notion联系人数据库
"""
import requests
import json
from datetime import datetime
# Notion API 配置
NOTION_API_KEY = "ntn_c43902219395mirQBetIfYoww1qKCAF14GBRUQeDee29o2"
DATABASE_ID = "2fb105ad-7873-81cf-90cc-dad8f1277ded" # 联系人数据库 ID
# 联系人信息
CONTACT_INFO = {
"name": "自己",
"email": "Yaxing_feng@dgmaorui.com",
"category": "个人",
"tags": ["自己", "公司邮箱"],
"notes": "公司邮箱,用于接收每日新闻摘要"
}
def add_contact_to_notion():
"""添加联系人到Notion数据库"""
print("=" * 60)
print("添加联系人到Notion")
print("=" * 60)
print(f"联系人: {CONTACT_INFO['name']}")
print(f"邮箱: {CONTACT_INFO['email']}")
print(f"分类: {CONTACT_INFO['category']}")
print("=" * 60)
# Notion API 端点
url = "https://api.notion.com/v1/pages"
# 请求头
headers = {
"Authorization": f"Bearer {NOTION_API_KEY}",
"Content-Type": "application/json",
"Notion-Version": "2022-06-28"
}
# 请求体
payload = {
"parent": {
"database_id": DATABASE_ID
},
"properties": {
"Name": {
"title": [
{
"text": {
"content": CONTACT_INFO["name"]
}
}
]
},
"Email": {
"email": CONTACT_INFO["email"]
},
"Category": {
"select": {
"name": CONTACT_INFO["category"]
}
},
"Tags": {
"multi_select": [
{"name": tag} for tag in CONTACT_INFO["tags"]
]
},
"Notes": {
"rich_text": [
{
"text": {
"content": CONTACT_INFO["notes"]
}
}
]
}
}
}
try:
# 发送请求
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
print("\n✅ 联系人添加成功!")
print("=" * 60)
print(f"联系人ID: {result['id']}")
print(f"联系人名称: {CONTACT_INFO['name']}")
print(f"邮箱: {CONTACT_INFO['email']}")
print("=" * 60)
return True
else:
print(f"\n❌ 添加失败")
print(f"状态码: {response.status_code}")
print(f"错误信息: {response.text}")
return False
except Exception as e:
print(f"\n❌ 发生错误: {e}")
return False
def main():
"""主函数"""
print("开始添加联系人到Notion...")
print()
success = add_contact_to_notion()
if success:
print("\n💡 提示:")
print("1. 联系人已添加到Notion数据库")
print("2. 分类标记为'个人'")
print("3. 标签包含'自己''公司邮箱'")
else:
print("\n🔧 解决方案:")
print("1. 检查Notion API密钥")
print("2. 检查数据库ID是否正确")
print("3. 检查网络连接")
if __name__ == "__main__":
main()