-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappigo_todo_export.py
executable file
·122 lines (102 loc) · 3.47 KB
/
appigo_todo_export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python
import sys
from os import path
import sqlite3
import datetime
tasktype = {
0:"task",
1: "project",
2: "contact",
6: "url"
}
recurrence_string = {
0: "",
1: "+1w",
2: "+1m",
3: "+1y",
5: "+2w",
7: "+6m",
9: "",
50: "+1m",
101:"+1w",
105: "+2w",
150: "+3d",
103: "+1y",
}
def convert_tasks(dbname):
"""
opens database file with name dbname
loads values from database and writes as org-mode formatted text to stdout
"""
connection = sqlite3.connect(dbname)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute("select name,type,type_data,recurrence,advanced_recurrence, task_id, parent_id, due_date, project_due_date, note from tasks where deleted=0 and completion_date=-62135769600.0 order by parent_id")
result = cursor.fetchall()
children = {}
no_parent = []
for r in result:
if r['parent_id'] is None:
no_parent.append(r)
elif r['parent_id'] ==u'':
no_parent.append(r)
else:
if r['parent_id'] in children:
children[r['parent_id']].append(r)
else:
children[r['parent_id']] =[r]
level=1
for task in no_parent:
convert_task(task,level)
if task['task_id'] in children:
for sub_task in children[task['task_id']]:
convert_task(sub_task,level+1)
connection.close()
def deadline(date,recurrence,advanced_recurrence):
if recurrence==0:
return "<"+date+ ">"
else:
return "<"+ date +" " + recurrence_string[recurrence]+ ">"
def double_to_date(d):
if d is None:
return ""
else:
return datetime.datetime.fromtimestamp(d).strftime("%Y-%m-%d %a %H:%M")
def convert_task(row,level):
"""converts a single task row"""
print level*'*',"TODO", row['name'].encode('utf-8')
#convert due_date to DEADLINE entry
if row['type']==1:
# for project use project_due_date
due_date = row['project_due_date']
else:
# for other than project use due_date
due_date = row['due_date']
if due_date < 64092211200.0:
print "DEADLINE:", \
deadline(double_to_date(due_date),
row['recurrence'],
row['advanced_recurrence'])
print ":PROPERTIES:"
print ":Tasktype:",tasktype[row['type']]
print ":type_data:", row['type_data'].encode('utf-8')
print ":recurrence:", row['recurrence']
print ":advanced_recurrence:", row['advanced_recurrence']
print ":task_id:", row['task_id']
print ":parent_id:", row['parent_id']
print ":due_date:", row['due_date']
print ":END:"
if row['note'] !='':
print row['note'].encode('utf8')
def main(argv):
if len(argv)<1:
inputfile = path.expanduser('~/Library/Containers/com.appigo.todomac/Data/Library/Application Support/Appigo Todo/AppigoTodo_v13.sqlitedb')
else:
inputfile = argv[0]
print "# -*- mode: org -*-"
print "#+TITLE: Import from Appigo Todo"
print "#+OPTIONS: ^:{}"
print ""
convert_tasks(inputfile)
if __name__ == "__main__":
main(sys.argv[1:])