From 7a86d284156199a0f3520978bd933eb1d1afc0f5 Mon Sep 17 00:00:00 2001 From: KWON Date: Tue, 22 Jul 2025 15:28:03 +0900 Subject: [PATCH] =?UTF-8?q?notion=5Fapi=EC=97=90=EC=84=9C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8D=98=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20con?= =?UTF-8?q?fig.py=20=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config.py | 12 +++++++++++- lib/notion_api.py | 12 ++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/config.py b/lib/config.py index 42f0880..d242aef 100644 --- a/lib/config.py +++ b/lib/config.py @@ -12,6 +12,16 @@ class Config: # 노션 API NOTION_API_SECRET = os.getenv('NOTION_API_SECRET') + NOTION_API_BASE = "https://api.notion.com/v1" + NOTION_VERSION = "2022-06-28" + + @classmethod + def get_notion_headers(cls): + return { + "Authorization": f"Bearer {cls.NOTION_API_SECRET}", + "Notion-Version": cls.NOTION_VERSION, + "Content-Type": "application/json" + } # 웹훅 서명 검증용 비밀키 (옵션) NOTION_WEBHOOK_SECRET = os.getenv('NOTION_WEBHOOK_SECRET', None) @@ -58,6 +68,6 @@ class Config: raise EnvironmentError(err_msg) else: print("필수 항목 검증 완료") - + # 초기 검증 실행 Config.validate() diff --git a/lib/notion_api.py b/lib/notion_api.py index adbcbf5..f85ef5c 100644 --- a/lib/notion_api.py +++ b/lib/notion_api.py @@ -13,8 +13,8 @@ from lib.config import Config from lib.common import EVENT_TYPE_LABELS def get_page_details(page_id: str) -> Optional[Dict]: - url = f"{NOTION_API_BASE}/pages/{page_id}" - response = requests.get(url, headers=HEADERS) + url = f"{Config.NOTION_API_BASE}/pages/{page_id}" + response = requests.get(url, headers=Config.HEADERS) if response.status_code == 200: return response.json() @@ -147,17 +147,17 @@ def fetch_entity_detail(entity_type: str, entity_id: str) -> Optional[Dict]: """ url = None if entity_type == "page": - url = f"{NOTION_API_BASE}/pages/{entity_id}" + url = f"{Config.NOTION_API_BASE}/pages/{entity_id}" elif entity_type == "database": - url = f"{NOTION_API_BASE}/databases/{entity_id}" + url = f"{Config.NOTION_API_BASE}/databases/{entity_id}" elif entity_type == "block": - url = f"{NOTION_API_BASE}/blocks/{entity_id}/children" + url = f"{Config.NOTION_API_BASE}/blocks/{entity_id}/children" else: logging.warning(f"알 수 없는 entity_type: {entity_type}") return None try: - response = requests.get(url, headers=HEADERS, timeout=5) + response = requests.get(url, headers=Config.HEADERS, timeout=5) response.raise_for_status() return response.json() except Exception as e: