-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcloseTask.py
64 lines (55 loc) · 1.65 KB
/
closeTask.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
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2020 Michael Schmidt-Korth
#
# GNU GPL v2.0 Licence. See https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
from __future__ import unicode_literals
import sys
from main import DEBUG, formatDate
from config import confNames, getConfigValue
from workflow import Workflow, Workflow3, ICON_WEB, ICON_CLOCK, ICON_WARNING, ICON_GROUP, web
def main(wf):
if len(wf.args):
query = wf.args[0]
else:
query = None
if query:
updateTask(query.split('/')[-1])
def updateTask(strTaskId):
'''Updates an existing Task and sets its status to 'Closed'.
----------
@param str strTaskId: Id of the Task to update.
'''
from workflow.notify import notify
if DEBUG > 0:
log.debug('[ Calling API to close task ]')
wf3 = Workflow3()
url = 'https://api.clickup.com/api/v2/task/' + strTaskId
headers = {}
headers['Authorization'] = getConfigValue(confNames['confApi'])
headers['Content-Type'] = 'application/json'
data = {}
data['status'] = 'Closed'
if DEBUG > 1:
log.debug(url)
log.debug(headers)
log.debug(data)
try:
import requests
request = requests.put(url, json = data, headers = headers)
request.raise_for_status()
result = request.json()
if DEBUG > 1:
log.debug('Response: ' + str(result))
notify('Closed Task', result['name'])
except Exception as exc:
log.debug('Error on HTTP request:' + str(exc))
wf3.add_item(title = 'Error connecting to ClickUp.', subtitle = 'Open configuration to check your parameters?', valid = True, arg = 'cu:config ', icon = 'error.png')
wf3.send_feedback()
exit()
if __name__ == "__main__":
wf = Workflow()
log = wf.logger
sys.exit(wf.run(main))