Skip to content

Commit

Permalink
Add "Create Trello card" script command (raycast#542)
Browse files Browse the repository at this point in the history
* Add "Create Trello Card" script command
* PR comments
* Punctuation
* Add logo
* Handle date parsing error
  • Loading branch information
mxkxf authored Aug 12, 2021
1 parent 8dad757 commit 2efcca9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions commands/apps/trello/create-trello-card.template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
Binary file added commands/apps/trello/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2efcca9

Please sign in to comment.