Skip to content

Commit

Permalink
google keep: assign to the note instance directly
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Jan 30, 2025
1 parent 3b2c02b commit 000c0de
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/formats/google_keep.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,45 @@ def convert_note(self, file_: Path):
title = note_keep.get("title", "")
if not title.strip():
title = common.unique_title()
self.logger.debug(f'Converting note "{title.replace("\n", "")}"')
self.logger.debug(f'Converting note "{title}"')

tags_keep = [
label["name"] for label in note_keep.get("labels", []) if "name" in label
note_imf = imf.Note(title, source_application=self.format)

note_imf.tags = [
imf.Tag(label["name"])
for label in note_keep.get("labels", [])
if "name" in label
]
if note_keep.get("isPinned"):
tags_keep.append("google-keep-pinned")
note_imf.tags.append(imf.Tag("google-keep-pinned"))

resources_keep = []
for resource_keep in note_keep.get("attachments", []):
resources_keep.append(
note_imf.resources.append(
imf.Resource(file_.parent.absolute() / resource_keep["filePath"])
)

# fall back to HTML if there is no plain text
if "textContent" in note_keep:
body = note_keep["textContent"]
note_imf.body = note_keep["textContent"]
elif (body_html := note_keep.get("textContentHtml")) is not None:
body = markdown_lib.common.markup_to_markdown(body_html)
note_imf.body = markdown_lib.common.markup_to_markdown(body_html)
elif (body_list := note_keep.get("listContent")) is not None:
# task list
list_items_md = []
for item in body_list:
bullet = "- [x] " if item["isChecked"] else "- [ ] "
list_items_md.append(f"{bullet}{item["text"]}")
body = "\n".join(list_items_md)
note_imf.body = "\n".join(list_items_md)
else:
body = ""
note_imf.body = ""
self.logger.debug("Couldn't obtain note body.")
if (annotations := note_keep.get("annotations")) is not None:
annotations_md = ["", "", "## Annotations", ""]
for annotation in annotations:
annotations_md.append(f"- <{annotation["url"]}>: {annotation["title"]}")
annotations_md.append("") # newline at the end
body += "\n".join(annotations_md)
note_imf.body += "\n".join(annotations_md)

note_imf = imf.Note(
title,
body,
source_application=self.format,
# Labels / tags don't have a separate id. Just use the name as id.
tags=[imf.Tag(tag) for tag in tags_keep],
resources=resources_keep,
)
if (value := note_keep.get("createdTimestampUsec")) is not None:
note_imf.created = common.timestamp_to_datetime(value // (10**6))
if (value := note_keep.get("userEditedTimestampUsec")) is not None:
Expand Down

0 comments on commit 000c0de

Please sign in to comment.