Skip to content

Commit

Permalink
feat: add notion token parameter to Exporter (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eun-chan Cho committed Jan 10, 2024
1 parent 073994a commit a93cf51
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions notion2md/console/commands/export_block.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys
import time

Expand All @@ -11,14 +10,14 @@
from notion2md.console.ui.indicator import progress
from notion2md.exporter.block import CLIExporter


ARGS_NEW_KEY_MAP = {
"id": "block_id",
"url": "block_url",
"name": "output_filename",
"path": "output_path",
"download": "download",
"unzipped": "unzipped",
"token": "token",
}


Expand All @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion notion2md/exporter/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,7 +26,7 @@ def __init__(
download=download,
unzipped=unzipped,
)
self._client = NotionClient()
self._client = NotionClient(token)
self._io = None
self._block_convertor = None

Expand Down
9 changes: 5 additions & 4 deletions notion2md/notion_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
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


@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):
Expand Down

0 comments on commit a93cf51

Please sign in to comment.