-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpy_notion.py
More file actions
37 lines (32 loc) · 1.12 KB
/
py_notion.py
File metadata and controls
37 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from loguru import logger
from . import NotionDatabase, NotionPage
from .block import NotionBlock
from .comment import NotionComment
from .core import InvalidTokenException
from .user import NotionUser
class PyNotion:
def __init__(self, token: str):
# Initialize PyNotion client with SECRET_TOKEN or API_TOKEN from Notion. Default value is None
self.token: str = token
if self.token is None or len(self.token) == 0:
# Raise error if token is not provided
logger.error(
"Invalid API token provided",
)
raise InvalidTokenException
logger.info(
"Successfully initialized PyNotion Client",
)
self.database: NotionDatabase
self.page: NotionPage
self.block: NotionBlock
self.user: NotionUser
self.comment: NotionComment
self.__initialize_modules()
def __initialize_modules(self) -> None:
# Initialize all the classes that correspond to different modules with secret token
self.database = NotionDatabase(token=self.token)
self.page = NotionPage(token=self.token)
self.block = NotionBlock(token=self.token)
self.user = NotionUser(token=self.token)
self.comment = NotionComment(token=self.token)