-
Notifications
You must be signed in to change notification settings - Fork 20
/
getThings3.py
155 lines (123 loc) · 4.8 KB
/
getThings3.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3
import webbrowser
import codecs
from os.path import expanduser, dirname, realpath
# Basic file info
home = expanduser("~")
sqlite_file = home + '/Library/Containers/com.culturedcode.ThingsMac/Data/Library/Application Support/Cultured Code/Things/Things.sqlite3'
fout = dirname(realpath(__file__)) + '/kanban.html'
mstr1 = []
mstr2 = []
def create_connection(db_file):
conn = sqlite3.connect(sqlite_file)
return conn
def select_all_tasks(conn):
cur = conn.cursor()
#This will get all area names and UUID
cur.execute("SELECT uuid, title FROM TMArea")
rowArea = cur.fetchall()
nbArea=len(rowArea)
#This will get all active project as long as they have due date
cur.execute("SELECT uuid, title, date(dueDate, 'unixepoch'), area FROM TMTask WHERE type = 1 AND trashed = 0 AND status = 0 AND dueDate != 0 ORDER BY dueDate" )
rowProj = cur.fetchall()
nbProj=len(rowProj)
#This will get all active project that do not have a due date
cur.execute("SELECT uuid, title, area FROM TMTask WHERE type = 1 AND (status = 0 AND trashed = 0 AND dueDate IS NULL) ORDER BY area" )
rowProj2 = cur.fetchall()
nbProj2=len(rowProj2)
#Extracting the # of active tasks for all projects
cur.execute("SELECT uuid, title, project, area FROM TMTask WHERE type = 0" )
rowTask = cur.fetchall()
nbTask=len(rowTask)
#print('Nb Areas:',nbArea, ' Nb Projects:',nbProj, nbProj2, ' Nb Tasks:',nbTask)
#Extracting the # of active (i.e. excluding completed) tasks for specific projects with existing due date
ip=0
itot=0
for row in rowProj:
getID=rowProj[ip][0]
cur.execute("SELECT uuid, title, date(dueDate, 'unixepoch') FROM TMTask WHERE status = 0 AND trashed = 0 AND project = '%s'" % getID)
icount = cur.fetchall()
ic=len(icount)
#concatenate the task count back into the tuple containing all previous information
rowProj[ip] += (ic,)
itot=itot+ic
mstr1.append("""<div id="box1">"""+ "<a href="+"things:///show?id="+rowProj[ip][0]+">"+rowProj[ip][1]+"</a>"+" ("+str(rowProj[ip][4])+") "+"""<span style="float:right;">"""+str(rowProj[ip][2])+"</span></div>")
ip=ip+1
#Extracting the # of active (i.e. excluding completed) tasks for the rest of the projects
ip=0
for row in rowProj2:
getID=rowProj2[ip][0]
cur.execute("SELECT uuid, title, date(dueDate, 'unixepoch') FROM TMTask WHERE status = 0 AND project = '%s'" % getID)
icount = cur.fetchall()
ic=len(icount)
#concatenate the task count back into the tuple containing all previous information
rowProj2[ip] += (ic,)
itot=itot+ic
if ic==0:
mstr2.append("""<div id="box3">"""+ "<a href="+"things:///show?id="+rowProj2[ip][0]+">"+rowProj2[ip][1]+"</a>"+" ("+str(rowProj2[ip][3])+") "+"</div>")
else:
mstr2.append("""<div id="box4">"""+ "<a href="+"things:///show?id="+rowProj2[ip][0]+">"+rowProj2[ip][1]+"</a>"+" ("+str(rowProj2[ip][3])+") "+"</div>")
ip=ip+1
#Create the HTML file on the fly
f = codecs.open(fout,'w','utf-8')
message = """<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="3col.css">
</head>
<body>
<div id="head">Things 3 - Project-Level Kanban View</div>
<div id="foot"><br />Copyright ©2018 Luc Beaulieu</div>
<div id="left1">
<div class="inner">
<h2>Upcoming Projects</h2>"""
f.write(message)
# time to fill first column of our Kanban Board
ip=0
for row in rowProj:
f.write(mstr1[ip])
ip=ip+1
# time to fill second column of our Kanban Board
message = """
</div>
</div>
<div id="left2">
<div class="inner">
<h2>No active tasks</h2>"""
f.write(message)
ip=0
for row in rowProj2:
if rowProj2[ip][3]==0:
f.write(mstr2[ip])
ip=ip+1
# time to fill third column of our Kanban Board
message = """
</div>
</div>
<div id="left3">
<div class="inner">
<h2>Other Projects</h2>"""
f.write(message)
ip=0
for row in rowProj2:
if rowProj2[ip][3]!=0:
f.write(mstr2[ip])
ip=ip+1
# let's close the whole thing
message = """
</div> </div>
</body>
</html>"""
f.write(message)
f.close()
def main():
# create a database connection
conn = create_connection(sqlite_file)
with conn:
select_all_tasks(conn)
#Change path to reflect file location and displauy the results
filename = 'file://'+fout
webbrowser.open_new_tab(filename)
if __name__ == '__main__':
main()