Created
May 14, 2022 20:23
-
-
Save emanuele-f/4fb7b06b65ee1c35023ba47cbf3d3bfe to your computer and use it in GitHub Desktop.
Convert huawei proprietary notes app db (note_pad.db) to standardnotes.com JSON format
This file contains 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 python3 | |
import json | |
import uuid | |
import sqlite3 | |
import os | |
import sys | |
from datetime import datetime | |
def ms_to_tstamp(ms): | |
dt = datetime.fromtimestamp(ms / 1000.0) | |
s = dt.isoformat() | |
return s[:-3] + "Z" | |
def new_note(created_at, updated_at, text): | |
note = { | |
"uuid": str(uuid.uuid4()), | |
"content_type": "Note", | |
"content": { | |
"title": "", | |
"text": text, | |
"references": [], | |
}, | |
"created_at": created_at, | |
"updated_at": updated_at, | |
} | |
return note | |
def main(): | |
if len(sys.argv) != 2: | |
print("Usage: %s note_pad.db" % os.path.basename(sys.argv[0])) | |
exit(1) | |
db_path = sys.argv[1] | |
db = sqlite3.connect(db_path) | |
cur = db.cursor() | |
cur.execute("select created, modified, content from notes where delete_flag=0 order by modified desc") | |
res = cur.fetchall() | |
db.close() | |
items = [] | |
for rec in res: | |
(created, modified, text) = rec | |
if text.startswith("Text|"): | |
text = text[5:] | |
note = new_note(ms_to_tstamp(created), ms_to_tstamp(modified), text) | |
items.append(note) | |
obj = {"items": items} | |
print(json.dumps(obj, indent=2)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment