Skip to content

Commit

Permalink
feat: add option to set custom tag for uploaded pages
Browse files Browse the repository at this point in the history
fix #23
  • Loading branch information
vzhd1701 committed Apr 7, 2022
1 parent 2a7b2ce commit 1c385e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions enex2notion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(
add_meta: bool,
add_pdf_preview: bool,
condense_lines: bool,
custom_tag: str,
):
self.import_root = import_root
self.mode = mode
Expand All @@ -72,6 +73,7 @@ def __init__(
self.add_meta = add_meta
self.add_pdf_preview = add_pdf_preview
self.condense_lines = condense_lines
self.custom_tag = custom_tag

def upload(self, enex_file: Path):
logger.info(f"Processing notebook '{enex_file.stem}'...")
Expand All @@ -83,6 +85,9 @@ def upload(self, enex_file: Path):
logger.debug(f"Skipping note '{note.title}' (already uploaded)")
continue

if self.custom_tag and self.custom_tag not in note.tags:
note.tags.append(self.custom_tag)

note_blocks = self._parse_note(note)
if not note_blocks:
continue
Expand Down Expand Up @@ -132,6 +137,7 @@ def cli(argv):
add_meta=args.add_meta,
add_pdf_preview=args.add_pdf_preview,
condense_lines=args.condense_lines,
custom_tag=args.tag,
)

for enex_input in args.enex_input:
Expand Down Expand Up @@ -227,6 +233,10 @@ def parse_args(argv):
" makes sense only with PAGE mode"
),
},
"--tag": {
"type": str,
"help": "add custom tag to uploaded notes",
},
"--condense-lines": {
"action": "store_true",
"default": False,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,11 @@ def test_bad_token(mock_api, fake_note_factory, caplog):
assert "Invalid token provided!" in caplog.text


def test_custom_tag(mock_api, fake_note_factory):
cli(["--tag", "test_tag", "fake.enex"])

fake_note_factory()[0].tags.append.assert_called_once_with("test_tag")


def test_cli_main_import():
from enex2notion import __main__

0 comments on commit 1c385e1

Please sign in to comment.