notes icon indicating copy to clipboard operation
notes copied to clipboard

Importing Google Keep notes difficulty

Open ryandikdan opened this issue 2 years ago • 0 comments

I tried to use the code to load in Google Keep notes, and it didn't do a great job. I wrote up something quick myself that takes care of check lists, text, and what I tried to make with attachments. It's shown below:

import os
import json
import shutil

os.makedirs("markdown/attachments")

for filename in os.listdir('Keep'):
     if filename.split('.')[-1] == 'json':
        data = json.load(open("Keep/"+filename, 'r', encoding="utf-8"))

        if "labels" in data:
            category_folder = data["labels"][0]['name']     #Uses first label...

            if not os.path.exists("markdown/"+category_folder):
                os.makedirs("markdown/"+category_folder)
        else:
            category_folder = ""

        if data["title"] == "":
            md_name = filename.split(".")[0]
        else:
            md_name = data["title"].replace('/',"_")
            for char in ['\\','+','=','?','(',')','<','>',':','*','"','|']:
                md_name = md_name.replace(char,"_")


        with open("markdown/"+category_folder+'/'+filename.split(".")[0]+".md", 'w+', encoding="utf-8") as md:
            # atachments and images
            if 'attachments' in data:
                if len(data['attachments']) > 0:
                    for attachment in data['attachments']:

                        attach_file = attachment["filePath"]
                        if attach_file not in os.listdir('Keep'):
                            attach_file = attach_file[:-3]+"png"
                        if attach_file not in os.listdir('Keep'):
                            attach_file = attach_file[:-3]+"jpg"
                        if attach_file not in os.listdir('Keep'):
                            attach_file = attach_file[:-3]+"3gp"

                        md.write("!["+attach_file+"](.attachments.9542/"+attach_file+")\n")
                        shutil.copyfile("Keep/"+attach_file, "markdown/attachments/"+attach_file)
            # free text
            if "textContent" in data:
                for line in data["textContent"].split('\n'):
                    md.write(line+'\n')
            # lists
            if "listContent" in data:
                for item in data["listContent"]:
                    if item["isChecked"] == False:
                        md.write("-[ ] "+item["text"]+"\n")
                    elif item["isChecked"] == True:
                        md.write("-[x] "+item["text"]+"\n")

Only issue I had is that when I load them all in. It actually works pretty okay with the lists, but the attachments can't be found by the notes app, even though I put them in the appropriate hidden attachment folder. It also seems that the notes app is randomly making new attachment folders, perhaps it's looking for them? If you could guide me about the formatting for attachments I'd really appreciate it so I can import my many notes appropriately!

ryandikdan avatar Sep 21 '23 01:09 ryandikdan