-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskcoach_test.py
executable file
·141 lines (122 loc) · 4.34 KB
/
taskcoach_test.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
#!/usr/bin/python3
# Program : taskcoach_test.py
# Version : 0.3.2
# Created by : petervdb
# Last updated by : petervdb
# Creation date : 29/09/2014
# Last updated : 11/04/2016
# Test Taskcoach version : 1.4.3
#
# You can use this script to analyse a Taskcoach tsk file
#
# ToDo
# Create subroutine to be able to go recursively into sub-tasks without limit (currenly limited to 5)
# Enable arguments to retrieve only specific data. For example: categories, task depth, priorities, dates
#
# Example execution:
# python3 taskcoach_test.py ./taskcoach_test.tsk
# ./taskcoach_test.py ./taskcoach_test.tsk
from sys import argv
from os.path import exists
import xml.etree.ElementTree as etree
import getopt
import json
def print_categories():
# find all categories
allcategories = root.findall('category')
print ("Let's display all categories:")
print(allcategories)
print("-----------------------------------------------------------------------------------")
def print_tasks():
# find all tasks
alltasks = root.findall('task')
print ("Let's display all tasks:")
print(alltasks)
print("-----------------------------------------------------------------------------------")
def check_taskcoach_file():
# Quit if file does not exist
if exists(taskfile):
tk_file = etree.parse(taskfile)
return(tk_file)
else:
print("Sorry, %s does not exist." % taskfile)
exit(1)
def parse_taskcoach_file(root):
count = 0
tasks = 0
cats = 0
for child in root:
# Display Element information
# print(child)
# Display content
print("> %s ", root[count].attrib)
# cur_text is a JSON string
cur_text = root[count].attrib
# A need the tag to figure out what I need to do with the JSON string
cur_tag = root[count].tag
# only works for tasks and categories
if cur_tag == "task":
tasks = tasks + 1
subject = cur_text['subject']
print("> Task %s : %s " % (tasks, subject))
if cur_tag == "category":
cats = cats + 1
subject = cur_text['subject']
print("> Category %s : %s " % (cats, subject))
print("Child elements of %s: %s " % (subject, len(root[count])))
if len(root[count]) > 0:
parse_child_object(count,subject)
print("-----------------------------------------------------------------------------------")
count = count + 1
def parse_child_object(count,subject):
print("> > > > > > > > > >")
print("> Will analyze child objects for %s." % subject)
count2 = 0
for child2 in root[count]:
print("> %s ", root[count][count2].attrib)
if len(root[count][count2]) > 0:
parse_child_object2(count,count2,subject)
count2 = count2 + 1
def parse_child_object2(count,count2,subject):
print(">> >> >> >> >> >> >> >> >> >>")
print(">> Will analyze child objects for %s." % subject)
count3 = 0
for child3 in root[count][count2]:
print(">> %s ", root[count][count2][count3].attrib)
if len(root[count][count2][count3]) > 0:
parse_child_object3(count,count2,count3,subject)
count3 = count3 + 1
def parse_child_object3(count,count2,count3,subject):
print(">>> >>> >>> >>> >>> >>> >>> >>> >>> >>>")
print(">>> Will analyze child objects for %s." % subject)
count4 = 0
for child4 in root[count][count2][count3]:
print(">>> %s ", root[count][count2][count3][count4].attrib)
if len(root[count][count2][count3][count4]) > 0:
parse_child_object4(count,count2,count3,count4,subject)
count4 = count4 + 1
def parse_child_object4(count,count2,count3,count4,subject):
print(">>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>>")
print(">>>> Will analyze child objects for %s." % subject)
count5 = 0
for child5 in root[count][count2][count3][count4]:
print(">>> %s ", root[count][count2][count3][count4][count5].attrib)
if len(root[count][count2][count3][count4][count5]) > 0:
print(">>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>")
count5 = count5 + 1
# This is a test program to analyze taskcoach files
print("This is a small program to analyse your Taskcoach file")
# The script requires the Taskcoach file as argument
# Quit if usage is not good
try:
script, taskfile = argv
except getopt.GetoptError:
print("Usage: %s <toachcoach_file.tsk>" % script)
exit(2)
tk_file = check_taskcoach_file()
root = tk_file.getroot()
print("Document root: %s " % root)
print("Child elements of root: %s " % len(root))
parse_taskcoach_file(root)
# print_tasks()
# print_categories()