From fe1644856e5113a1010dc251be4281006acbb14e Mon Sep 17 00:00:00 2001 From: John Place Date: Fri, 24 Feb 2023 11:53:24 -0500 Subject: [PATCH] ToodleDo XML Import Tool Tool to aid migrateing from ToodleDo (toodledo.com) to MTT. It will take the file that that toodledo.com exports (toodledo.xml) and import it into the todolist.db sqlite data base. --- toodledoimport.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 toodledoimport.py diff --git a/toodledoimport.py b/toodledoimport.py new file mode 100644 index 0000000..652be15 --- /dev/null +++ b/toodledoimport.py @@ -0,0 +1,69 @@ +#!/bin/env python3 + +from time import time +from uuid import uuid4 +from xmltodict import parse +import sqlite3 + +listids = {} +dbdata = [] + +fp = open("toodledo.xml") +xmldata = parse(fp.read()) + +dbcon = sqlite3.connect("todolist.db") + +# Create a Context to list_id table +dbcur = dbcon.cursor() +result = dbcur.execute("SELECT id,name from lists") +for row in result.fetchall(): + listids.update({row[1]:row[0]}) +dbcur.close() + +for nodes in xmldata['xml']['item']: + title = nodes['title'] + title.replace("'","''") + + # Encase all notes inside code fences + if nodes['note'] == None: + note = '' + else: + note = '```\n'+nodes['note']+'\n```' + note = note.replace("'","''") + + try: + listid = listids[nodes['context']] + except: + print(f"Fail no List ID for: {nodes['context']}") + exit(1) + + ow = 1 + dbdata.append(( + str(uuid4()), + listid, + int(time()), + int(time()), + title, + note, + ow + )) + +dbcur = dbcon.cursor() +dbcur.executemany( + '''INSERT INTO todolist ( + uuid, + list_id, + d_created, + d_edited, + title, + note, + ow + ) VALUES(?,?,?,?,?,?,?)''' + ,dbdata +) + +dbcur.close() +dbcon.commit() +dbcon.close() + +print(f"Loaded {len(dbdata)} Records")