Created
June 6, 2024 00:54
-
-
Save echus/ce7cd43ec18edaad8105ca37349af41b to your computer and use it in GitHub Desktop.
Google Keep to Simplenote import script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Google Keep export to Simplenote import script. | |
Converts Google Keep Takeout archive into a Simplenote-compatible .json file | |
for direct import into Simplenote. | |
""" | |
import json | |
import os | |
import glob | |
import uuid | |
from datetime import datetime | |
KEEP_PATH = "./Keep" | |
def convert_timestamp(timestamp): | |
# Convert Keep timestamp in epoch microseconds to ISO format | |
return ( | |
datetime.utcfromtimestamp(timestamp // 1000000) | |
.replace(microsecond=keep["createdTimestampUsec"] % 1000000) | |
.isoformat(timespec="milliseconds") | |
+ "Z" | |
) | |
# Simplenote-formatted JSON dict | |
data = { | |
"activeNotes": [], | |
"trashedNotes": [], | |
} | |
# Iterate over all .json note files in KEEP_PATH | |
files = glob.glob(os.path.join(KEEP_PATH, "*.json")) | |
print("Processing", len(files), "notes.") | |
for filename in files: | |
with open(filename, "r") as f: | |
keep = json.load(f) | |
# Convert text and list content | |
content = keep["title"] + "\r\n" | |
if "textContent" in keep.keys(): | |
content = content + keep["textContent"] | |
elif "listContent" in keep.keys(): | |
for item in keep["listContent"]: | |
if item["isChecked"]: | |
content = content + "- [x] " + item["text"] + "\r\n" | |
else: | |
content = content + "- [ ] " + item["text"] + "\r\n" | |
# Populate labels | |
labels = [label["name"] for label in keep.get("labels", [])] | |
# Convert timestamps | |
created = convert_timestamp(keep["createdTimestampUsec"]) | |
updated = convert_timestamp(keep["userEditedTimestampUsec"]) | |
data["activeNotes"].append( | |
{ | |
"id": str(uuid.uuid4()), # Simplenote import ignores this | |
"content": content, | |
"creationDate": created, | |
"lastModified": updated, | |
"pinned": keep.get("isPinned", False), | |
"tags": labels, | |
} | |
) | |
with open("./keep.json", "w") as f: | |
json.dump(data, f) | |
print("Finished! Generated keep.json for import into Simplenote.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment