Skip to content

Commit

Permalink
fix: set note update time to created time if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed May 11, 2022
1 parent 4b9bd35 commit 8f3f5b1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
6 changes: 4 additions & 2 deletions enex2notion/enex_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ def _process_note(note_raw: dict):
note_tags = [note_tags]

now = datetime.now()
date_created = isoparse(note_raw.get("created", now.isoformat()))
date_updated = isoparse(note_raw.get("updated", date_created.isoformat()))

return EvernoteNote(
title=note_raw.get("title", "Untitled"),
created=isoparse(note_raw.get("created", now.isoformat())),
updated=isoparse(note_raw.get("updated", now.isoformat())),
created=date_created,
updated=date_updated,
content=note_raw.get("content", ""),
tags=note_tags,
author=note_attrs.get("author", ""),
Expand Down
68 changes: 68 additions & 0 deletions tests/test_enex_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,74 @@ def test_iter_notes_single(fs):
]


def test_iter_notes_single_no_update_time(fs):
test_enex = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd">
<en-export export-date="20211218T085932Z" application="Evernote" version="10.25.6">
<note>
<title>test1</title>
<created>20211118T085332Z</created>
<note-attributes>
</note-attributes>
<content>test</content>
</note>
</en-export>
"""
fs.create_file("test.enex", contents=test_enex)

notes = list(iter_notes(Path("test.enex")))

assert notes == [
EvernoteNote(
title="test1",
created=datetime.datetime(2021, 11, 18, 8, 53, 32, tzinfo=tzutc()),
updated=datetime.datetime(2021, 11, 18, 8, 53, 32, tzinfo=tzutc()),
content="test",
tags=[],
author="",
url="",
is_webclip=False,
resources=[],
),
]


def test_iter_notes_single_no_time(fs, mocker):
test_enex = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd">
<en-export export-date="20211218T085932Z" application="Evernote" version="10.25.6">
<note>
<title>test1</title>
<note-attributes>
</note-attributes>
<content>test</content>
</note>
</en-export>
"""
fs.create_file("test.enex", contents=test_enex)

test_time = datetime.datetime(2021, 11, 18, 8, 53, 32, tzinfo=tzutc())

mock_dt = mocker.patch("enex2notion.enex_parser.datetime")
mock_dt.now.return_value = test_time

notes = list(iter_notes(Path("test.enex")))

assert notes == [
EvernoteNote(
title="test1",
created=test_time,
updated=test_time,
content="test",
tags=[],
author="",
url="",
is_webclip=False,
resources=[],
),
]


def test_iter_notes_single_hash(fs):
test_enex = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd">
Expand Down

0 comments on commit 8f3f5b1

Please sign in to comment.