From e9c122989258a6daccdbbe60eec53b0b2273b225 Mon Sep 17 00:00:00 2001 From: echo724 Date: Sat, 26 Aug 2023 13:17:43 +0900 Subject: [PATCH] feat: add notion token parameter to `Exporter` --- notion2md/console/commands/export_block.py | 4 ++-- notion2md/exporter/block.py | 3 ++- notion2md/notion_api.py | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/notion2md/console/commands/export_block.py b/notion2md/console/commands/export_block.py index 432afce..ead16d9 100644 --- a/notion2md/console/commands/export_block.py +++ b/notion2md/console/commands/export_block.py @@ -1,4 +1,3 @@ -import os import sys import time @@ -11,7 +10,6 @@ from notion2md.console.ui.indicator import progress from notion2md.exporter.block import CLIExporter - ARGS_NEW_KEY_MAP = { "id": "block_id", "url": "block_url", @@ -19,6 +17,7 @@ "path": "output_path", "download": "download", "unzipped": "unzipped", + "token": "token", } @@ -27,6 +26,7 @@ class ExportBlockCommand(Command): description = "Export a Notion block object to markdown." options = [ + option("token", "t", "The token of your Notion account.", flag=False), option("url", "u", "The url of Notion block object.", flag=False), option("id", "i", "The id of Notion block object.", flag=False), option("name", "n", "The name of Notion block object", flag=False), diff --git a/notion2md/exporter/block.py b/notion2md/exporter/block.py index e466f44..98c9162 100644 --- a/notion2md/exporter/block.py +++ b/notion2md/exporter/block.py @@ -16,6 +16,7 @@ def __init__( output_path: str = None, download: bool = False, unzipped: bool = False, + token: str = None, ): self._config = Config( block_id=block_id, @@ -25,7 +26,7 @@ def __init__( download=download, unzipped=unzipped, ) - self._client = NotionClient() + self._client = NotionClient(token) self._io = None self._block_convertor = None diff --git a/notion2md/notion_api.py b/notion2md/notion_api.py index bce90eb..14cb40c 100644 --- a/notion2md/notion_api.py +++ b/notion2md/notion_api.py @@ -8,9 +8,9 @@ def singleton(cls): instance = {} - def get_instance(): + def get_instance(token=""): if cls not in instance: - instance[cls] = cls() + instance[cls] = cls(token) return instance[cls] return get_instance @@ -18,8 +18,9 @@ def get_instance(): @singleton class NotionClient: - def __init__(self): - token = self._get_env_variable() + def __init__(self, token=""): + if not token: + token = self._get_env_variable() self._client = Client(auth=token) def _get_env_variable(self):