1
|
|
|
#!/usr/bin/env python3 |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
"""OPML Plugin for the Thing 3 CLI.""" |
5
|
|
|
|
6
|
|
|
from __future__ import print_function |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
import xml.etree.ElementTree as ETree |
10
|
|
|
from xml.etree.ElementTree import Element, SubElement |
11
|
|
|
from xml.dom import minidom |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class Things3OPML: |
15
|
|
|
"""OPML Plugin for Thing 3 CLI.""" |
16
|
|
|
|
17
|
|
|
@staticmethod |
18
|
|
|
def get_top(): |
19
|
|
|
"""Get first element.""" |
20
|
|
|
top = Element("opml") |
21
|
|
|
head = SubElement(top, "head") |
22
|
|
|
title = SubElement(head, "title") |
23
|
|
|
title.text = "Things 3 Database" |
24
|
|
|
return top |
25
|
|
|
|
26
|
|
|
@staticmethod |
27
|
|
|
def print(top): |
28
|
|
|
"""Print pretty XML.""" |
29
|
|
|
xmlstr = minidom.parseString(ETree.tostring(top)).toprettyxml(indent=" ") |
30
|
|
|
print(xmlstr) |
31
|
|
|
|
32
|
|
|
def print_tasks(self, tasks): |
33
|
|
|
"""Print pretty XML of selected tasks.""" |
34
|
|
|
top = self.get_top() |
35
|
|
|
body = SubElement(top, "body") |
36
|
|
|
for task in tasks: |
37
|
|
|
SubElement(body, "outline").set("text", task["title"]) |
38
|
|
|
self.print(top) |
39
|
|
|
|
40
|
|
|
def print_all(self, things3): |
41
|
|
|
"""Print.""" |
42
|
|
|
top = self.get_top() |
43
|
|
|
body = SubElement(top, "body") |
44
|
|
|
|
45
|
|
|
for area in things3.get_areas(): |
46
|
|
|
area_element = SubElement(body, "outline") |
47
|
|
|
area_element.set("text", area["title"]) |
48
|
|
|
for task in things3.get_task(area["uuid"]): |
49
|
|
|
SubElement(area_element, "outline").set("text", task["title"]) |
50
|
|
|
for project in things3.get_projects(area["uuid"]): |
51
|
|
|
project_element = SubElement(area_element, "outline") |
52
|
|
|
project_element.set("text", project["title"]) |
53
|
|
|
for task in things3.get_task(None, project["uuid"]): |
54
|
|
|
SubElement(project_element, "outline").set("text", task["title"]) |
55
|
|
|
self.print(top) |
56
|
|
|
|