-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
250 lines (207 loc) · 9.32 KB
/
main.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import trello
import wunderlist
import json
#############################
# Functions
#############################
def _get_config(config_file):
# Gets config from config.json
try:
cfg = json.load(open(config_file))
return cfg
except Exception as e:
print(" [ERR] Cannot get config from %s (%s)" % (config_file, e) )
quit()
def process_wunderlist_list(list, test_mode):
trello_board = list['title']
if test_mode == 'True':
## Add for easy cleanup
trello_board = 'Test Board'
print("Creating a new board '%s'" % (trello_board) )
# Note, this automatically creates 'To Do' 'Doing' 'Done' Lists
rc = trello.create_board(trello_board, 'Wunderlist List Id: ' + str(list['id']))
if rc == 2:
print(" [ERR] already exists")
elif rc != 0:
print("Error")
# Get NON COMPLETE tasks
print("Getting active tasks...")
tasks = wunderlist.get_tasks_by_id(list['id'], False)
# Check if completed tasks should be skipped
if cfg['SkipCompletedTasks'] == 'True':
print("Skipping completed tasks")
else:
# Get COMPLETE tasks
print("Getting completed tasks...")
c_tasks = wunderlist.get_tasks_by_id(list['id'], True)
tasks = (tasks + c_tasks)
for task in tasks:
#print(task)
trello_assigned_team_member = ''
trello_card = task['title']
#print("\n [TASK] %s (Completed: %s) (Starred: %s)" % (trello_card, task['completed'], task['starred']) )
if str(task['completed']) == 'True':
trello_list = 'Done'
else:
if str(task['starred']) == 'True':
# Starred not completed = Doing
trello_list = 'Doing'
trello_assigned_team_member = cfg['TrelloTeamMemberId']
else:
# Not starred not completed = To Do
trello_list = 'To Do'
# Add wunderlist notes to the trello card description
# Need new code here
notes = wunderlist.get_task_notes_by_id(task['id'])
card_desc = ''
if len(notes) > 0:
for note in notes:
if 'content' in note:
if note['content'] != "\n" and len(note['content']) > 0:
#print("Adding note to card: %s" % (note['content']))
card_desc = card_desc + note['content']
# if notes[0]['content'] != '\n':
# card_desc = notes[0]['content']
# #print(" [Notes] %s" % (card_desc) )
# Create Trello Card
closed = "false"
print("Creating card '%s'" % (trello_card) )
rc = trello.create_card(trello_board, trello_list, trello_card, card_desc, trello_assigned_team_member, closed)
if rc['code'] == 2:
print(" [ERR] already exists")
elif rc['code'] != 0:
print("Error")
else:
new_card_id = rc['id']
# Add comments as Trello actions
# Skip if Error 2 above to avoid duplicate actions
if rc['code'] != 2:
#print(task)
comments = wunderlist.get_task_comments_by_id(task['id'])
for comment in comments:
# Wunderlist currently publisheds Author->id,name,avatar, but not email
if 'text' in comment:
# Added for issue #3 from Github
commentString = "(From " + comment['author']['name'] + "): " + comment['text']
#print(" [COMMENT] %s)" % (comment['text']) )
print(" Adding action to [%s][%s][%s]" % (trello_board, trello_list, trello_card) )
#rc = trello.create_card_comment(trello_board, trello_list, trello_card, comment['text'])
# Added for issue #3 from Github
rc = trello.create_card_comment(trello_board, trello_list, trello_card, commentString)
if rc['code'] != 0:
print(" [ERR] %s" % rc['error'])
if cfg['ArchiveCompletedTasks'] == 'True' and trello_list == 'Done':
print(" Archiving card '%s'" % (trello_card))
trello.archive_card_by_id(new_card_id)
def process_wunderlist_list_from_json(list, test_mode):
trello_board = list['title']
if test_mode == 'True':
## Add for easy cleanup
trello_board = 'Test Board'
print("Creating a new board '%s'" % (trello_board) )
# Note, this automatically creates 'To Do' 'Doing' 'Done' Lists
rc = trello.create_board(trello_board, 'Wunderlist List Id: ' + str(list['id']))
if rc == 2:
print(" [ERR] already exists")
elif rc != 0:
print("Error")
# Cycle through tasks
for task in list['tasks']:
trello_assigned_team_member = ''
trello_card = task['title']
if cfg['SkipCompletedTasks'] == 'True' and str(task['completed']) == 'True':
print("Skipping completed task '%s'" % task['title'])
else:
#print("\n [TASK] %s (Completed: %s) (Starred: %s)" % (trello_card, task['completed'], task['starred']) )
if str(task['completed']) == 'True':
trello_list = 'Done'
else:
if str(task['starred']) == 'True':
# Starred not completed = Doing
trello_list = 'Doing'
trello_assigned_team_member = cfg['TrelloTeamMemberId']
else:
# Not starred not completed = To Do
trello_list = 'To Do'
# Add wunderlist notes to the trello card description
if len(task['notes']) > 0:
if task['notes'][0]['content'] != '\n':
card_desc = task['notes'][0]['content']
#print(" [Notes] %s" % (card_desc) )
else:
card_desc = ''
# Create Trello Card
closed = "false"
print("Creating card '%s'" % (trello_card) )
rc = trello.create_card(trello_board, trello_list, trello_card, card_desc, trello_assigned_team_member, closed)
if rc['code'] == 2:
print(" [ERR] already exists")
elif rc['code'] != 0:
print("Error")
else:
new_card_id = rc['id']
# Add comments as Trello actions
# Skip if Error 2 above to avoid duplicate actions
if rc['code'] != 2:
for comment in task['comments']:
#print(" [COMMENT] %s)" % (comment['text']) )
print(" Adding action to [%s][%s][%s]" % (trello_board, trello_list, trello_card) )
rc = trello.create_card_comment(trello_board, trello_list, trello_card, comment['text'])
if rc['code'] != 0:
print("Error")
if cfg['ArchiveCompletedTasks'] == 'True' and trello_list == 'Done':
print("Archiving card '%s'" % (trello_card))
rc = trello.archive_card_by_id(new_card_id)
if rc['code'] != 0:
print("Error")
################################################################
# Example 1: Get data from Wunderlist API, push to Trello
################################################################
# Get Config
cfg = _get_config('config.json')
# Generate a frozenset of excluded lists in lower case
excluded_lists = ( a.strip() for a in cfg['ExcludedLists'].lower().split(",") )
excluded_lists = frozenset(excluded_lists)
print("Gettings lists from Wunderlist API")
lists = wunderlist.get_lists()
for list in lists:
print("\n ===================================================")
print("\n[LIST] %s" % (list['title']) )
# Skip if list is excluded
if list['title'].lower() in excluded_lists:
print("- Skipping excluded list: %s" % list['title'])
else:
# test_mode always pushes to a Trello board named 'Test Board'
print("Processing list from Wunderlist API...")
process_wunderlist_list(list=list, test_mode='False')
quit()
# ###################################################################
# # Example 2: Get data from Wunderlist json export, push to Trello
# ###################################################################
#
# # Get Config
# cfg = _get_config('config.json')
#
# # Sets the Trello board name to "Test Board" for easy cleanup
# test_mode = 'True'
#
# # Generate a frozenset of excluded lists in lower case
# excluded_lists = ( a.strip() for a in cfg['ExcludedLists'].lower().split(",") )
# excluded_lists = frozenset(excluded_lists)
#
# # Get data from Wunder list export file
# lists = wunderlist.get_wunderlist_lists_from_json(cfg['WunderlistExport'])
#
# # Cycle through data (Lists, Tasks)
# for list in lists:
#
# print("\n ===================================================")
# print("\n[LIST] %s" % (list['title']) )
#
# # Skip if list is excluded
# if list['title'].lower() in excluded_lists:
# print("- Skipping excluded list: %s" % list['title'])
# else:
# # test_mode always pushes to a Trello board named 'Test Board'
# print("Processing list from json export...")
# process_wunderlist_list_from_json(list=list, test_mode=test_mode)