Skip to content

Commit

Permalink
fix: update note last edit time after upload
Browse files Browse the repository at this point in the history
fix #29
  • Loading branch information
vzhd1701 committed May 10, 2022
1 parent 587404a commit d5dfa95
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 278 deletions.
15 changes: 15 additions & 0 deletions enex2notion/enex_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from notion.block import CollectionViewPageBlock, PageBlock
from notion.client import NotionClient
from notion.collection import CollectionRowBlock
from notion.operations import build_operation
from progress.bar import Bar
from requests import HTTPError, codes

Expand Down Expand Up @@ -65,6 +66,20 @@ def upload_note(root, note: EvernoteNote, note_blocks):
# Set proper name after everything is uploaded
new_page.title = note.title

_update_edit_time(new_page, note.updated)


def _update_edit_time(page, date):
page._client.submit_transaction( # noqa: WPS437
build_operation(
id=page.id,
path="last_edited_time",
args=int(date.timestamp() * 1000),
table=page._table, # noqa: WPS437
),
update_last_edited=False,
)


def _make_page(note, root):
tmp_name = f"{note.title} [UNFINISHED UPLOAD]"
Expand Down
2 changes: 1 addition & 1 deletion tests/cassettes/test_upload_note.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["9dff3d3f-f648-489a-aa64-2d934a50afa7", "db0089f1-c576-4466-a01b-099828e57f7c", "01cf9e15-4dcc-4c99-8171-8f7b2f9f4f88"]
["bb265ccd-323f-487d-8d93-d29bd7ebde94", "7f6247a3-4ab6-430d-91a4-ae1a56625444", "8d979085-bbf3-4dcf-92f0-58b91e254745"]
155 changes: 90 additions & 65 deletions tests/cassettes/test_upload_note.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/cassettes/test_upload_note_db.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["a8f49246-2835-454a-b566-f8dce9219641", "21549268-e1af-4c07-8775-08d3ea3c12d4", "cf309b68-4c52-42b1-a13d-c1065dc493b5", "27d4ed52-c500-40c9-a8cf-fea2834f402d", "f5498f0c-6168-4d68-bbdc-f3375e2fe994", "691f4d70-2001-46a3-9fc1-4ea717a18ae6"]
["7e3fbf0a-f976-4c0b-8802-6ca00ea7b1ba", "f9b2d177-eba7-4548-a11b-bfd6493e058c", "55d28a90-be0e-4bf4-89c3-b0bed18dfa16", "94314b26-0014-4c95-b84d-546daf1bd5bd", "411932de-e3d0-4ac0-9833-84cd1115b597", "06f9a6fa-1b33-4520-b0a0-fab449e15f1b"]
283 changes: 154 additions & 129 deletions tests/cassettes/test_upload_note_db.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/cassettes/test_upload_note_with_file.uuid4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["661ab913-8c08-4f16-9633-9da09c885bdb", "e19eb1e9-d148-4cf5-a642-3e65eec53514", "c9f79dec-ccaa-4897-b2f8-94c6d9e27cc6"]
["f06bd880-a490-4293-9fea-7b261577fb43", "1bd49f77-8152-4a9d-963c-b78c23b96a52", "905fe845-b976-4885-888f-579b73e79219"]
185 changes: 105 additions & 80 deletions tests/cassettes/test_upload_note_with_file.yaml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion tests/test_enex_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_upload_note_db(notion_test_page):
test_note = EvernoteNote(
title="test1",
created=datetime(2021, 11, 18, 0, 0, 0, tzinfo=tzutc()),
updated=datetime(2021, 11, 18, 0, 0, 0, tzinfo=tzutc()),
updated=datetime(2021, 11, 19, 0, 0, 0, tzinfo=tzutc()),
content="<en-note><div>test</div></en-note>",
tags=[],
author="",
Expand All @@ -267,6 +267,9 @@ def test_upload_note_db(notion_test_page):

assert test_row.title == "test1"

assert test_row.created == datetime(2021, 11, 18, 0, 0, 0)
assert test_row.updated == datetime(2021, 11, 19, 0, 0, 0)

assert len(test_row.children) == 1
assert isinstance(test_row.children[0], TextBlock)
assert test_row.children[0].title == "test"

0 comments on commit d5dfa95

Please sign in to comment.