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

Import From Google Keep #31

Closed
11raob opened this issue Jan 30, 2025 · 3 comments
Closed

Import From Google Keep #31

11raob opened this issue Jan 30, 2025 · 3 comments
Labels
bug Something isn't working google-keep

Comments

@11raob
Copy link

11raob commented Jan 30, 2025

Unknown reason for why some notes are converted for import into QOwnNotes from Keep zip file and other are ignored
Some of the Keep notes are written to *.md file by this tool but not all. See following partial list of 189 processed files. You can see that more than half in this list only have a file name but no contents---zero byte file.

-rw-r--r-- 1 root root     0 Jan 30 02:03 'Cancel all call forwarding_.md'
-rw-r--r-- 1 root root     0 Jan 30 02:03 'Chevrolet Silverado black pickup truck.md'
-rw-r--r-- 1 root root   173 Jan 30 02:03 'Client Electronic Benefit Transfer.md'
-rw-r--r-- 1 root root     0 Jan 30 02:03 'Coimbatore Day Trip to Black Thunder Amusement Par.md'
-rw-r--r-- 1 root root     0 Jan 30 02:03 'Coimbatore Journey (17 January 2020).md'
-rw-r--r-- 1 root root    33 Jan 30 02:03  Colognes.md
-rw-r--r-- 1 root root    17 Jan 30 02:03 'Colonel for Bandarban visit.md'
-rw-r--r-- 1 root root    66 Jan 30 02:03  Cookbook.md
-rw-r--r-- 1 root root     0 Jan 30 02:03  Corruption.md
-rw-r--r-- 1 root root     0 Jan 30 02:03  CUNYfirst.md
-rw-r--r-- 1 root root     0 Jan 30 02:03 'Curaçao June 2021.md'
-rw-r--r-- 1 root root     0 Jan 30 02:03 'CV additions.md'
-rw-r--r-- 1 root root     0 Jan 30 02:03 'Delay tactics.md'
-rw-r--r-- 1 root root     0 Jan 30 02:03 'Dream on 20221201.md'

**OS is . . . **
linux-based manjaro 24.2.1 Yonada

To Reproduce
Use the same command:

./jimmy-cli-linux './Keep/takeout-20250123T101543Z-001.zip' --format google_keep --frontmatter qownnotes --local-resource-folder attachments --local-image-folder media

Output was the following:

[01/29/25 04:36:26] INFO     Jimmy 0.0.44 (Pandoc 3.6.1)                                                                                                                                     
                    INFO     Importing notes from "/data/Nextcloud/rb/Google Takeout/Keep/takeout-20250123T101543Z-001.zip"                                                                  
                    INFO     Start parsing                                                                                                                                                   
                    INFO     Finished parsing: 1 notebooks, 189 notes, 5 resources, 1 tags                                                                                                   
                    INFO     Start filtering                                                                                                                                                 
                    INFO     Finished filtering: 1 notebooks, 189 notes, 5 resources, 1 tags                                                                                                 
                    INFO     Start writing to file system                                                                                                                                    
                    WARNING  Note "20250129T093625Z - Jimmy Import from google_keep/Moheskhali Adina Temple.md" exists already. New name: "Moheskhali Adina Temple_0001.md". Links may point 
                             to the wrong note.                                                                                                                                              
                    WARNING  Note "20250129T093625Z - Jimmy Import from google_keep/To do.md" exists already. New name: "To do_0001.md". Links may point to the wrong note.                  
                    WARNING  Note "20250129T093625Z - Jimmy Import from google_keep/To do.md" exists already. New name: "To do_0002.md". Links may point to the wrong note.                  
                    INFO     Converted notes successfully to Markdown: "20250129T093625Z - Jimmy Import from google_keep". Please verify that everything was converted correctly.            
                    INFO     Feel free to open an issue on Github, write a message at the Joplin forum, Obsidian forum or an email.                                                          

Notebooks  100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00]
Notes      100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 189/189 [00:00<00:00]
Resources  100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00]
Tags       100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00]

takeout-20250123T101543Z-001.zip

@11raob 11raob added the bug Something isn't working label Jan 30, 2025
@marph91
Copy link
Owner

marph91 commented Jan 30, 2025

Thanks for the report. I will test with the provided file later today.

Update: I was able to reproduce and fix it. You can try release v0.0.45.

There is one limitation: The nesting level of task lists is not available in the exported file. So all lists are flat.

@11raob
Copy link
Author

11raob commented Jan 30, 2025

Thanks for the quick fix. I tried also keep_to_markdown.py at https://gitlab.com/-/snippets/2002921, but that python script misses things also and the code is not correct.

Here's the corrected version of keep_to_markdown_rev1.py in case you are interested in comparing notes with your utility.

#!/bin/bash

import logging
import json
import os
import sys


class InvalidNote(Exception):
    def __init__(self, message):
        super().__init__(f"Invalid note {message}")
        self.message = f"Invalid note {message}"


def note_to_string(source: dict) -> str:
    # TODO Markdown escapes
    if "title" in source and len(source["title"]):
        contents = f"# {source['title']}\n\n"
    else:
        contents = ""

    if "listContent" in source:
        for li in source["listContent"]:
            checkmark = "x" if li["isChecked"] else ""
            contents += f"- [{checkmark}] {li['text']}\n"
    elif "textContent" in source:
        contents += source["textContent"]
    else:
        raise InvalidNote(source)
    return contents


def write_note(contents: str, name: str, out_dir: str):
    counter = 0
    suffix = ""
    while counter < 1000:  # Safeguard
        try:
            # Use base name from source path instead of full source path
            base_name = os.path.basename(name).replace('.json', '')
            file_path = os.path.join(out_dir, f"{base_name}{suffix}.md")
            with open(file_path, "x") as f:
                f.write(contents)
            break
        except OSError:
            counter += 1
            suffix = f"-{counter}"


def convert_note(source_path: str, dest_dir: str):
    with open(source_path) as source:
        note_dict = json.load(source)
    write_note(note_to_string(note_dict), source_path, dest_dir)


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)  # Set up logging

    source = sys.argv[1]
    dest_dir = sys.argv[2]

    if not os.path.isdir(dest_dir):
        os.mkdir(dest_dir)

    if os.path.isfile(source):
        convert_note(source, dest_dir)
    elif os.path.isdir(source):
        with os.scandir(source) as it:
            for entry in it:
                if not entry.is_file() or not entry.name.endswith(".json"):
                    continue
                try:
                    convert_note(entry.path, dest_dir)
                except (InvalidNote, OSError) as e:
                    logging.error("Failed to convert note %s: %s", entry.path, str(e))
    else:
        logging.error("Cannot access %s", sys.argv[1])
        sys.exit(1)

@marph91
Copy link
Owner

marph91 commented Jan 31, 2025

Thanks for the reference. I couldn't find any feature that is present in the script, but missing in jimmy (except of the title in the first line).

If there is anything missing in jimmy, feel free to report it here.

@marph91 marph91 closed this as completed Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working google-keep
Projects
None yet
Development

No branches or pull requests

2 participants