mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
Merge fe1644856e into c2ff9a8a7d
This commit is contained in:
commit
334e7e76e9
1 changed files with 69 additions and 0 deletions
69
toodledoimport.py
Normal file
69
toodledoimport.py
Normal file
|
|
@ -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")
|
||||
Loading…
Reference in a new issue