notion_api에서 사용하던 정보를 config.py 로 이동
This commit is contained in:
@ -12,6 +12,16 @@ class Config:
|
|||||||
|
|
||||||
# 노션 API
|
# 노션 API
|
||||||
NOTION_API_SECRET = os.getenv('NOTION_API_SECRET')
|
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)
|
NOTION_WEBHOOK_SECRET = os.getenv('NOTION_WEBHOOK_SECRET', None)
|
||||||
@ -58,6 +68,6 @@ class Config:
|
|||||||
raise EnvironmentError(err_msg)
|
raise EnvironmentError(err_msg)
|
||||||
else:
|
else:
|
||||||
print("필수 항목 검증 완료")
|
print("필수 항목 검증 완료")
|
||||||
|
|
||||||
# 초기 검증 실행
|
# 초기 검증 실행
|
||||||
Config.validate()
|
Config.validate()
|
||||||
|
|||||||
@ -13,8 +13,8 @@ from lib.config import Config
|
|||||||
from lib.common import EVENT_TYPE_LABELS
|
from lib.common import EVENT_TYPE_LABELS
|
||||||
|
|
||||||
def get_page_details(page_id: str) -> Optional[Dict]:
|
def get_page_details(page_id: str) -> Optional[Dict]:
|
||||||
url = f"{NOTION_API_BASE}/pages/{page_id}"
|
url = f"{Config.NOTION_API_BASE}/pages/{page_id}"
|
||||||
response = requests.get(url, headers=HEADERS)
|
response = requests.get(url, headers=Config.HEADERS)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.json()
|
return response.json()
|
||||||
@ -147,17 +147,17 @@ def fetch_entity_detail(entity_type: str, entity_id: str) -> Optional[Dict]:
|
|||||||
"""
|
"""
|
||||||
url = None
|
url = None
|
||||||
if entity_type == "page":
|
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":
|
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":
|
elif entity_type == "block":
|
||||||
url = f"{NOTION_API_BASE}/blocks/{entity_id}/children"
|
url = f"{Config.NOTION_API_BASE}/blocks/{entity_id}/children"
|
||||||
else:
|
else:
|
||||||
logging.warning(f"알 수 없는 entity_type: {entity_type}")
|
logging.warning(f"알 수 없는 entity_type: {entity_type}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, headers=HEADERS, timeout=5)
|
response = requests.get(url, headers=Config.HEADERS, timeout=5)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user