-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_tasks.py
97 lines (74 loc) · 3.33 KB
/
get_tasks.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
import json
import csv
import re
from datetime import datetime
def extract_tasks_from_trello(json_file):
with open(json_file, 'r') as f:
data = json.load(f)
tasks = []
for card in data['cards']:
# Skip cards with the label 'infra'
labels = [label['name'] for label in card['labels']]
if 'infra' in labels:
continue
if 'Frontend' in labels:
continue
task = {'name': card['name'], 'description': card['desc'],
'labels': [label['name'] for label in card['labels']],
'due_date': card['due'] if 'due' in card else None, 'short_url': card['shortUrl'],
'closed': card['closed'], 'complete_date':'', 'estimate':0}
# Check if list ID matches and set 'done' field accordingly
if check_if_done(card['idList']):
task['done'] = True
else:
task['done'] = False
# Extract estimate from card name using regular expression
match = re.search(r'\[(\d+)\]', task['name'])
if match:
task['estimate'] = int(match.group(1))
else:
task['estimate'] = None
# Find the first action where the task was moved to the desired list
for action in data['actions']:
if action['type'] == 'updateCard' and action['data']['card']['id'] == card['id']:
if 'listAfter' in action['data']:
if check_if_ready_for_demo(action['data']['listAfter']['id']):
move_date = datetime.strptime(action['date'], "%Y-%m-%dT%H:%M:%S.%fZ")
task['complete_date'] = move_date.strftime("%Y-%m-%d %H:%M:%S")
if task['complete_date'] == '':
for action in data['actions']:
if action['type'] == 'updateCard' and action['data']['card']['id'] == card['id']:
if 'listAfter' in action['data']:
if check_if_done(action['data']['listAfter']['id']):
move_date = datetime.strptime(action['date'], "%Y-%m-%dT%H:%M:%S.%fZ")
task['complete_date'] = move_date.strftime("%Y-%m-%d %H:%M:%S")
print('--')
print(task['name'], task['complete_date'])
print("--")
tasks.append(task)
return tasks
def check_if_ready_for_demo(listId):
listDoneId1 = '642c5aedd95db65295aa3200' #готово к демо
# listDoneId2 = '642c5aedd95db65295aa3201' #Done
return listId == listDoneId1
def check_if_done(listId):
# listDoneId1 = '642c5aedd95db65295aa3200' #готово к демо
listDoneId2 = '642c5aedd95db65295aa3201' #Done
return listId == listDoneId2
def save_tasks_to_csv(tasks, csv_file):
fieldnames = ['Task Name', 'URL', 'Archived', 'Complete Date', 'Estimate']
with open(csv_file, 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
for task in tasks:
writer.writerow({
'Task Name': task['name'],
'URL': task['short_url'],
'Archived': task['closed'],
'Complete Date': task['complete_date'],
'Estimate': task['estimate'],
})
json_file = 'board.json'
csv_file = 'tasks.csv'
tasks = extract_tasks_from_trello(json_file)
save_tasks_to_csv(tasks, csv_file)