-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrello-export.py
executable file
·176 lines (116 loc) · 3.89 KB
/
trello-export.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
#!/usr/bin/env python
import sys
import json
import csv
from trello import TrelloSession
board = TrelloSession().boards['Platform Status Board']
projects_list = board.lists['Programs/Projects']
project_urls = {}
for p in projects_list.cards:
proj = projects_list.cards[p]
project_urls[proj.shortUrl] = proj
csvwriter = csv.writer(sys.stdout, delimiter=',', quotechar='"')
n = 0
data = []
for c in board.cards:
n += 1
card = board.cards[c]
#print(card.name)
#if not ('Need UX' in card.labels or 'Developer Tools' in card.labels):
# continue
if card.listId not in board.listsById:
continue
card_list = board.listsById[card.listId]
if card_list.name in ['Programs/Projects', '2017 Platform OKR\'s']:
continue
labels = []
for l in card.labels:
labels.append(card.labels[l].name)
need_priority = ""
if 'Need Priority' in labels:
need_priority = 'x'
# labels.remove('Need Priority')
need_review = ""
if 'Needs Review' in labels:
need_review = 'x'
# labels.remove('Needs Review')
old_priority = ""
for p in range(0, 12):
ps = 'Old-P{}'.format(p)
if ps in labels:
old_priority = str(p)
labels.remove(ps)
break
new_priority = ""
for p in range(0, 4):
ps = 'P{}'.format(p)
if ps in labels:
new_priority = str(p)
labels.remove(ps)
break
if len(labels) == 0:
labels = ""
desc = card.desc
proj = ""
p = desc.split("Project: ")
if len(p) < 2:
p = desc.split("Projects: ")
if len(p) > 1:
proj_url = p[1].split('\n')[0]
if proj_url in project_urls:
proj = project_urls[proj_url].name
r = desc.split('Resource needs (in 1/2 person years): ')
res = ""
if len(r) > 1:
res = r[1].split('\n')[0].strip().replace("'", '"')
if len(res) > 0:
if not (res.startswith('(') and res.endswith(')')) :
print("Invalid resource string '{}' in card {}" \
.format(res, card.name))
continue
parts = res[1:-1].split(' ')
total = float(parts[0])
try:
res = json.loads(' '.join(parts[1:]))
except Exception as e:
print("Invalid resource declaration {} in card {}." \
.format(res, card.name))
continue
sum = 0.0
for a in res:
sum += res[a]
if sum != total:
print("Total ({:.02f}) does not match sum ({:.02f}) in card {}" \
.format(total, sum, card.name))
responsible = ""
team = ""
for m in card.members:
member = board.membersById[m]
if member.fullName.endswith(" Team"):
team = member.fullName
else:
responsible += member.fullName + ", "
if responsible.endswith(", "):
responsible = responsible[:-2]
data.append([card.name, proj, card_list.name, str(labels), old_priority,
new_priority, need_priority, need_review, team, responsible,
card.id, res])
resources = set()
for entry in data:
res = entry[-1]
for a in res:
resources.add(a)
csvwriter.writerow(["Title", "Project", "List Name", "Labels", "Old Priority",
"New Priority", "Needs Priority", "Needs Review", "Team",
"Responsible", "id"] +
['res-' + r for r in sorted(resources)])
for entry in data:
res = entry.pop()
rl = []
if res != "":
for r in sorted(resources):
if r in res and res[r] != 0:
rl.append(res[r])
else:
rl.append("")
csvwriter.writerow(entry + rl)