Skip to content

Commit 2efcca9

Browse files
authored
Add "Create Trello card" script command (raycast#542)
* Add "Create Trello Card" script command * PR comments * Punctuation * Add logo * Handle date parsing error
1 parent 8dad757 commit 2efcca9

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
3+
# Dependency: This script requires the following Python libraries: `dateparser`, `requests`
4+
# Install them with `pip install dateparser requests`
5+
6+
# Required parameters:
7+
# @raycast.schemaVersion 1
8+
# @raycast.title Create Card
9+
# @raycast.packageName Trello
10+
# @raycast.mode compact
11+
12+
# Optional parameters:
13+
# @raycast.icon ./images/logo.png
14+
# @raycast.argument1 { "type": "text", "placeholder": "Card title" }
15+
# @raycast.argument2 { "type": "text", "placeholder": "Due date (e.g. today)", "optional": true }
16+
17+
# Documentation:
18+
# @raycast.description Create a new Trello card
19+
# @raycast.author Michael Francis
20+
# @raycast.authorURL https://github.com/mikefrancis
21+
22+
import sys
23+
import requests
24+
import dateparser
25+
26+
# To generate an API key/token, head to https://trello.com/app-key
27+
TRELLO_KEY = ''
28+
TRELLO_TOKEN = ''
29+
# To find the Board ID, head to https://api.trello.com/1/members/me/boards?key={TRELLO_KEY}&token={TRELLO_TOKEN}
30+
# To find the List ID, head to https://api.trello.com/1/boards/{BOARD_ID}/lists?key={TRELLO_KEY}&token={TRELLO_TOKEN}
31+
TRELLO_LIST_ID = ''
32+
33+
if not TRELLO_KEY:
34+
print('Command not configured correctly. Missing variable: TRELLO_KEY')
35+
exit(1)
36+
37+
if not TRELLO_TOKEN:
38+
print('Command not configured correctly. Missing variable: TRELLO_TOKEN')
39+
exit(1)
40+
41+
if not TRELLO_LIST_ID:
42+
print('Command not configured correctly. Missing variable: TRELLO_LIST_ID')
43+
exit(1)
44+
45+
name = sys.argv[1]
46+
due_date = sys.argv[2]
47+
48+
payload = {
49+
'key': TRELLO_KEY,
50+
'token': TRELLO_TOKEN,
51+
'idList': TRELLO_LIST_ID,
52+
'name': name,
53+
'pos': 'top',
54+
}
55+
56+
if due_date:
57+
try:
58+
datetime = dateparser.parse(due_date)
59+
payload['due'] = datetime.strftime('%Y-%m-%d')
60+
except:
61+
pass
62+
63+
response = requests.post('https://api.trello.com/1/cards', data=payload)
64+
65+
if not response.ok :
66+
print(response.reason)
67+
exit(1)
2.33 KB
Loading

0 commit comments

Comments
 (0)