Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2013 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChewingPencils/5525567 to your computer and use it in GitHub Desktop.
Save ChewingPencils/5525567 to your computer and use it in GitHub Desktop.
Drafts to Trello - Used for a Drafts app action. #python #pythonista #url_scheme
#!/usr/bin/env python
# Sean Korzdorfer
# Mon 2013-05-04
import argparse
import requests
import sys
import json
import webbrowser
import pprint
pp = pprint.PrettyPrinter(indent=4)
def main(args):
### Please Set API Credentials ###
# Set your Trello API Key
args['key'] = ''
# Set your Trello API Token
args['token'] = ''
# Set position of new card - top, or bottom, or an numerical value
args['pos'] = 'top'
bugger = True
### Do Not Edit Below This Line ###
if bugger:
print '\n\n---- drafts2trello starting ----\n\n'
print 'Command Line Parsed As:\n\t'
# Trello API POST card URL
card_add_url = ""
# Build argument payload for API card
payload = {'name': args['card_text'], 'idList' : args['list_id'], 'key' : args['key'], 'token': args['token'], 'desc' : args['card_note'], 'pos' : args['pos']}
#if args['card_note'] != "":
# payload = {'desc' : args['card_note']}
if bugger:
print '\n\nPayload for API call\n\n'
# Make API call. r is the response.
r =, data=payload)
# Parse API response
parsed_json = json.loads(r.content)
# Test API response for expected results
if r.status_code == and bugger:
print '\n\nHTTP Response From Task Note Request:\n\t'
print('\n\n---- drafts2trello ending ----\n\n')"drafts://")
elif r.status_code == and not bugger:"drafts://")
print 'Sorry. There was an error. Your card was not created.'
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('list_id', metavar='N', nargs='+', help='The ID of the list to add tne new card to')
parser.add_argument('-t', '--card', action='store', dest='card_text', nargs='+', help='The text which will appear in the card title')
parser.add_argument('-n', '--note', action='store', dest='card_note', nargs='*', help='Card Description')
parser.add_argument('-v','--version', action='version', version='%(prog)s 1.')
results = parser.parse_args()
# Will raise traceback error if missing
if results.list_id > 0:
args = {'list_id': ' '.join(results.list_id)}
# There is a task note, add it to the dictionary
if results.card_text:
args['card_text'] = ' '.join(results.card_text)
# If there is a task tag, add it to the dictionary
if results.card_note:
args['card_note'] = ' '.join(results.card_note)
args['card_note'] = ""
Copy link

wildeyes commented Jul 4, 2013

Hey ChewingPencils, how do I use your script? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment