Passed
Push — master ( fde0cc...eef757 )
by Alexander
01:33
created

things3.things3_kanban   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 65
dl 0
loc 121
rs 10
c 0
b 0
f 0
wmc 16

5 Functions

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