Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add notion token parameter to Exporter #52

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading