|
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
|
|
|
__author__ = "Luc Beaulieu and Alexander Willner" |
|
9
|
|
|
__copyright__ = "Copyright 2018 Luc Beaulieu / 2020 Alexander Willner" |
|
10
|
|
|
__credits__ = ["Luc Beaulieu", "Alexander Willner"] |
|
11
|
|
|
__license__ = "unknown" |
|
12
|
|
|
__version__ = "1.2.0" |
|
13
|
|
|
__maintainer__ = "Alexander Willner" |
|
14
|
|
|
__email__ = "[email protected]" |
|
15
|
|
|
__status__ = "Development" |
|
16
|
|
|
|
|
17
|
|
|
import codecs |
|
18
|
|
|
from os.path import dirname, realpath |
|
19
|
|
|
from os import environ |
|
20
|
|
|
from random import shuffle |
|
21
|
|
|
from things3 import Things3 |
|
22
|
|
|
|
|
23
|
|
|
# Basic config |
|
24
|
|
|
ANONYMIZE = bool(environ.get('ANONYMIZE')) |
|
25
|
|
|
|
|
26
|
|
|
# Basic variables |
|
27
|
|
|
FILE_HTML = dirname(realpath(__file__)) + '/kanban-static.html' |
|
28
|
|
|
|
|
29
|
|
|
THINGS3 = Things3() |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
def anonymize(word): |
|
33
|
|
|
"""Scramble output for screenshots.""" |
|
34
|
|
|
|
|
35
|
|
|
if ANONYMIZE is True: |
|
36
|
|
|
word = list(word) |
|
37
|
|
|
shuffle(word) |
|
38
|
|
|
word = ''.join(word) |
|
39
|
|
|
return word |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def write_html_column(cssclass, file, header, rows): |
|
43
|
|
|
"""Create a column in the output.""" |
|
44
|
|
|
|
|
45
|
|
|
file.write("<div class='column'><div class=''>" + |
|
46
|
|
|
"<h2 class='" + cssclass + "'>" + header + |
|
47
|
|
|
"<span class='size'>" + str(len(rows)) + |
|
48
|
|
|
"</span></h2>") |
|
49
|
|
|
|
|
50
|
|
|
for row in rows: |
|
51
|
|
|
task_uuid = str(row[0]) if row[0] is not None else '' |
|
52
|
|
|
task_title = anonymize(str(row[1])) if row[1] is not None else '' |
|
53
|
|
|
context_title = anonymize(str(row[2])) if row[2] is not None else '' |
|
54
|
|
|
context_uuid = str(row[3]) if row[3] is not None else '' |
|
55
|
|
|
deadline = str(row[4]) if row[4] is not None else '' |
|
56
|
|
|
|
|
57
|
|
|
task_link = '<a href="things:///show?id=' + task_uuid + '">' + \ |
|
58
|
|
|
task_title + '</a>' if task_uuid != '' else task_title |
|
59
|
|
|
context_link = '<a href="things:///show?id=' + context_uuid + '">' + \ |
|
60
|
|
|
context_title + '</a>' if context_uuid != '' else context_title |
|
61
|
|
|
css_class = 'hasProject' if context_title != '' else 'hasNoProject' |
|
62
|
|
|
css_class = 'hasDeadline' if deadline != '' else css_class |
|
63
|
|
|
|
|
64
|
|
|
file.write('<div class="box">' + task_link + |
|
65
|
|
|
'<div class="deadline">' + deadline + '</div>' + |
|
66
|
|
|
'<div class="area ' + css_class + '">' + context_link + |
|
67
|
|
|
'</div>' + |
|
68
|
|
|
'</div>') |
|
69
|
|
|
file.write("</div></div>") |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
def write_html_header(file): |
|
73
|
|
|
"""Write HTML header.""" |
|
74
|
|
|
|
|
75
|
|
|
message = """ |
|
76
|
|
|
<!DOCTYPE html> |
|
77
|
|
|
<html> |
|
78
|
|
|
<head> |
|
79
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
80
|
|
|
<link rel="stylesheet" href="../resources/kanban.css"> |
|
81
|
|
|
<title>KanbanView for Things 3</title> |
|
82
|
|
|
</head> |
|
83
|
|
|
|
|
84
|
|
|
<body> |
|
85
|
|
|
<header> |
|
86
|
|
|
<a href="#" onclick="refresh();" title="click to refresh"> |
|
87
|
|
|
<img class="logo" src="../resources/logo.png" alt="logo"> |
|
88
|
|
|
</a> |
|
89
|
|
|
</header> |
|
90
|
|
|
<article class='some-page-wrapper'> |
|
91
|
|
|
<div class='row'> |
|
92
|
|
|
""" |
|
93
|
|
|
file.write(message) |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
def write_html_footer(file): |
|
97
|
|
|
"""Write HTML footer.""" |
|
98
|
|
|
|
|
99
|
|
|
message = """ |
|
100
|
|
|
</div> |
|
101
|
|
|
</article> |
|
102
|
|
|
<footer class="footer"><br /> |
|
103
|
|
|
Copyright ©2018 Luc Beaulieu / 2020 Alexander Willner |
|
104
|
|
|
</footer></body></html>""" |
|
105
|
|
|
file.write(message) |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
def write_html_columns(file): |
|
109
|
|
|
"""Write HTML columns.""" |
|
110
|
|
|
|
|
111
|
|
|
write_html_column("color1", file, "Backlog", THINGS3.get_someday()) |
|
112
|
|
|
write_html_column("color5", file, "Upcoming", THINGS3.get_upcoming()) |
|
113
|
|
|
write_html_column("color3", file, "Waiting", THINGS3.get_waiting()) |
|
114
|
|
|
write_html_column("color4", file, "Inbox", THINGS3.get_inbox()) |
|
115
|
|
|
write_html_column("color2", file, "MIT", THINGS3.get_mit()) |
|
116
|
|
|
write_html_column("color6", file, "Today", THINGS3.get_today()) |
|
117
|
|
|
write_html_column("color7", file, "Next", THINGS3.get_anytime()) |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
def main(): |
|
121
|
|
|
"""Convert Things 3 database to Kanban HTML view.""" |
|
122
|
|
|
|
|
123
|
|
|
with codecs.open(FILE_HTML, 'w', 'utf-8') as file: |
|
124
|
|
|
write_html_header(file) |
|
125
|
|
|
write_html_columns(file) |
|
126
|
|
|
write_html_footer(file) |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
if __name__ == "__main__": |
|
130
|
|
|
main() |
|
131
|
|
|
|