forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-trello-card.template.py
executable file
·67 lines (53 loc) · 1.79 KB
/
create-trello-card.template.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
#!/usr/bin/env python3
# Dependency: This script requires the following Python libraries: `dateparser`, `requests`
# Install them with `pip install dateparser requests`
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Create Card
# @raycast.packageName Trello
# @raycast.mode compact
# Optional parameters:
# @raycast.icon ./images/logo.png
# @raycast.argument1 { "type": "text", "placeholder": "Card title" }
# @raycast.argument2 { "type": "text", "placeholder": "Due date (e.g. today)", "optional": true }
# Documentation:
# @raycast.description Create a new Trello card
# @raycast.author Michael Francis
# @raycast.authorURL https://github.com/mikefrancis
import sys
import requests
import dateparser
# To generate an API key/token, head to https://trello.com/app-key
TRELLO_KEY = ''
TRELLO_TOKEN = ''
# To find the Board ID, head to https://api.trello.com/1/members/me/boards?key={TRELLO_KEY}&token={TRELLO_TOKEN}
# To find the List ID, head to https://api.trello.com/1/boards/{BOARD_ID}/lists?key={TRELLO_KEY}&token={TRELLO_TOKEN}
TRELLO_LIST_ID = ''
if not TRELLO_KEY:
print('Command not configured correctly. Missing variable: TRELLO_KEY')
exit(1)
if not TRELLO_TOKEN:
print('Command not configured correctly. Missing variable: TRELLO_TOKEN')
exit(1)
if not TRELLO_LIST_ID:
print('Command not configured correctly. Missing variable: TRELLO_LIST_ID')
exit(1)
name = sys.argv[1]
due_date = sys.argv[2]
payload = {
'key': TRELLO_KEY,
'token': TRELLO_TOKEN,
'idList': TRELLO_LIST_ID,
'name': name,
'pos': 'top',
}
if due_date:
try:
datetime = dateparser.parse(due_date)
payload['due'] = datetime.strftime('%Y-%m-%d')
except:
pass
response = requests.post('https://api.trello.com/1/cards', data=payload)
if not response.ok :
print(response.reason)
exit(1)