Files
home-automation-backend/recorder/notion_handle.py

34 lines
1.1 KiB
Python
Raw Normal View History

2024-07-23 15:33:23 +02:00
import os
from datetime import datetime
from dotenv import load_dotenv
from notion_client import AsyncClient as Client
class NotionClient:
def __init__(self) -> None:
load_dotenv()
self._notion = Client(auth=os.environ["NOTION_TOKEN"])
self._page_id = "3cf594afd0754497ba0a93b94912b897"
self._table_id = "9828b56c53de46c794673fe1d01ad522"
async def note(self, now: datetime, status: str) -> None:
formatted_date = now.strftime("%Y-%m-%d")
formatted_time = now.strftime("%H:%M")
await self._notion.blocks.children.append(
block_id=self._table_id,
children=[
{
"object": "block",
"type": "table_row",
"table_row": {
"cells": [
[{"type": "text", "text": {"content": formatted_date}}],
[{"type": "text", "text": {"content": formatted_time}}],
[{"type": "text", "text": {"content": status}}],
],
},
},
],
)