|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
|
|
4
|
|
|
"""KanbanView (static) for Things 3.""" |
|
5
|
|
|
|
|
6
|
|
|
from __future__ import print_function |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
import codecs |
|
10
|
|
|
from os import getcwd |
|
11
|
|
|
from things3.things3 import Things3 |
|
12
|
|
|
|
|
13
|
|
|
# Basic variables |
|
14
|
|
|
FILE_HTML = getcwd() + "/kanban-static.html" |
|
15
|
|
|
THINGS3 = Things3() |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
def write_html_column(cssclass, file, header, rows): |
|
19
|
|
|
"""Create a column in the output.""" |
|
20
|
|
|
|
|
21
|
|
|
file.write( |
|
22
|
|
|
"<div class='column'><div class=''>" |
|
23
|
|
|
+ "<h2 class='h2 " |
|
24
|
|
|
+ cssclass |
|
25
|
|
|
+ "'>" |
|
26
|
|
|
+ header |
|
27
|
|
|
+ "<span class='size'>" |
|
28
|
|
|
+ str(len(rows)) |
|
29
|
|
|
+ "</span></h2>" |
|
30
|
|
|
) |
|
31
|
|
|
|
|
32
|
|
|
for row in rows: |
|
33
|
|
|
task_uuid = str(row["uuid"]) if row["uuid"] is not None else "" |
|
34
|
|
|
task_title = str(row["title"]) if row["title"] is not None else "" |
|
35
|
|
|
context_title = str(row["context"]) if row["context"] is not None else "" |
|
36
|
|
|
context_uuid = ( |
|
37
|
|
|
str(row["context_uuid"]) if row["context_uuid"] is not None else "" |
|
38
|
|
|
) |
|
39
|
|
|
deadline = str(row["due"]) if row["due"] is not None else "" |
|
40
|
|
|
|
|
41
|
|
|
task_link = ( |
|
42
|
|
|
'<a href="things:///show?id=' + task_uuid + '">' + task_title + "</a>" |
|
43
|
|
|
if task_uuid != "" |
|
44
|
|
|
else task_title |
|
45
|
|
|
) |
|
46
|
|
|
context_link = ( |
|
47
|
|
|
'<a href="things:///show?id=' + context_uuid + '">' + context_title + "</a>" |
|
48
|
|
|
if context_uuid != "" |
|
49
|
|
|
else context_title |
|
50
|
|
|
) |
|
51
|
|
|
css_class = "hasProject" if context_title != "" else "hasNoProject" |
|
52
|
|
|
css_class = "hasDeadline" if deadline != "" else css_class |
|
53
|
|
|
|
|
54
|
|
|
file.write( |
|
55
|
|
|
'<div class="box">' |
|
56
|
|
|
+ task_link |
|
57
|
|
|
+ '<div class="deadline">' |
|
58
|
|
|
+ deadline |
|
59
|
|
|
+ "</div>" |
|
60
|
|
|
+ '<div class="area ' |
|
61
|
|
|
+ css_class |
|
62
|
|
|
+ '">' |
|
63
|
|
|
+ context_link |
|
64
|
|
|
+ "</div>" |
|
65
|
|
|
+ "</div>" |
|
66
|
|
|
) |
|
67
|
|
|
file.write("</div></div>") |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
def write_html_header(file): |
|
71
|
|
|
"""Write HTML header.""" |
|
72
|
|
|
|
|
73
|
|
|
message = """ |
|
74
|
|
|
<!DOCTYPE html> |
|
75
|
|
|
<html> |
|
76
|
|
|
<head> |
|
77
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
78
|
|
|
<link rel="stylesheet" href="./resources/kanban.css"> |
|
79
|
|
|
<title>KanbanView for Things 3</title> |
|
80
|
|
|
</head> |
|
81
|
|
|
|
|
82
|
|
|
<body> |
|
83
|
|
|
<header> |
|
84
|
|
|
<a href="https://kanbanview.app" |
|
85
|
|
|
title="visit product page" target="_blank"> |
|
86
|
|
|
<picture id="app"> |
|
87
|
|
|
<source class="logo" srcset="resources/logo-dark.png" |
|
88
|
|
|
media="(prefers-color-scheme: dark)"> |
|
89
|
|
|
<img class="logo" src="resources/logo.png" alt="logo"> |
|
90
|
|
|
</picture> |
|
91
|
|
|
</a> |
|
92
|
|
|
</header> |
|
93
|
|
|
<article class='some-page-wrapper'> |
|
94
|
|
|
<div class='row'> |
|
95
|
|
|
""" |
|
96
|
|
|
file.write(message) |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
def write_html_footer(file): |
|
100
|
|
|
"""Write HTML footer.""" |
|
101
|
|
|
|
|
102
|
|
|
message = """ |
|
103
|
|
|
</div> |
|
104
|
|
|
</article> |
|
105
|
|
|
<footer class="footer"><br /> |
|
106
|
|
|
Copyright ©2020 Alexander Willner |
|
107
|
|
|
</footer></body></html>""" |
|
108
|
|
|
file.write(message) |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
def write_html_columns(file): |
|
112
|
|
|
"""Write HTML columns.""" |
|
113
|
|
|
|
|
114
|
|
|
write_html_column("color1", file, "Backlog", THINGS3.get_someday()) |
|
115
|
|
|
write_html_column("color8", file, "Grooming", THINGS3.get_cleanup()) |
|
116
|
|
|
write_html_column("color5", file, "Upcoming", THINGS3.get_upcoming()) |
|
117
|
|
|
write_html_column("color3", file, "Waiting", THINGS3.get_waiting()) |
|
118
|
|
|
write_html_column("color4", file, "Inbox", THINGS3.get_inbox()) |
|
119
|
|
|
write_html_column("color2", file, "MIT", THINGS3.get_mit()) |
|
120
|
|
|
write_html_column("color6", file, "Today", THINGS3.get_today()) |
|
121
|
|
|
write_html_column("color7", file, "Next", THINGS3.get_anytime()) |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
def main(output): |
|
125
|
|
|
"""Convert Things 3 database to Kanban HTML view.""" |
|
126
|
|
|
|
|
127
|
|
|
with output as file: |
|
128
|
|
|
write_html_header(file) |
|
129
|
|
|
write_html_columns(file) |
|
130
|
|
|
write_html_footer(file) |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
if __name__ == "__main__": |
|
134
|
|
|
with codecs.open(FILE_HTML, "w", "utf-8") as target: |
|
135
|
|
|
main(target) |
|
136
|
|
|
|