"""
Notion API操作モジュール
"""
import requests
from typing import List, Dict, Any
class NotionManager:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.notion.com/v1"
self.headers = {
"Authorization": f"Bearer {api_key}",
"Notion-Version": "2022-06-28",
}
def get_database_records(self, database_id: str):
url = f"{self.base_url}/databases/{database_id}/query"
response = requests.post(url, headers=self.headers)
return response.json().get("results", [])
def get_sellers(self, sellers_db_id: str):
records = self.get_database_records(sellers_db_id)
sellers = []
for record in records:
seller_info = {
"id": record["id"],
"name": record["properties"]["出品者名"]["title"][0]["plain_text"],
"mercari_id": record["properties"]["メルカリアカウントID"]["rich_text"][0]["plain_text"],
}
sellers.append(seller_info)
return sellers4つのPythonモジュールと実装ガイドをまとめてダウンロードできます。
pip install requests selenium
export NOTION_API_KEY="..." export SELLERS_DB_ID="..." export LINE_NOTIFY_TOKEN="..."