Last active
March 30, 2016 01:48
-
-
Save codemonkey85/ff58384a1a1d40e4103f86c8177e4ef6 to your computer and use it in GitHub Desktop.
A python script, meant to run on iOS via Pythonista and from Workflow, to get a list of all of the Trello cards assigned to you with the provided app key and token, as well as the provided board ID and username.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# Workflow script available here: http://bit.ly/1PEvd1S | |
import platform | |
if platform.system() == 'Darwin': | |
if platform.machine().startswith('iP'): | |
import console | |
import clipboard | |
import webbrowser | |
import urllib2 | |
import urllib | |
import json | |
import sys | |
clArgs = sys.argv[1].split(',') | |
appKey = clArgs[0] | |
appToken = clArgs[1] | |
boardId = clArgs[2] | |
userName = clArgs[3] | |
MyCards = [] | |
args = { 'key': appKey, | |
'token': appToken, | |
'filter': 'open'} | |
lists_url = "https://api.trello.com/1/boards/%s/lists?%s" % (boardId, urllib.urlencode(args)) | |
try: | |
data = urllib2.urlopen(lists_url) | |
except urllib2.HTTPError as inst: | |
raise Exception("Key or Token incorrect") | |
lists = json.loads(data.read()) | |
args = { | |
'fields': 'all', | |
'key': appKey, | |
'token': appToken | |
} | |
for li in lists: | |
cards_url = "https://api.trello.com/1/lists/%s/cards?%s" % (li['id'], urllib.urlencode(args)) | |
try: | |
cardsdata = urllib2.urlopen(cards_url) | |
except urllib2.HTTPError as inst: | |
raise Exception("Key or Token incorrect") | |
cards = json.loads(cardsdata.read()) | |
for card in cards: | |
members_url = "https://api.trello.com/1/cards/%s/members?%s" % (card['id'], urllib.urlencode(args)) | |
try: | |
membersdata = urllib2.urlopen(members_url) | |
except urllib2.HTTPError as inst: | |
raise Exception("Key or Token incorrect") | |
members = json.loads(membersdata.read()) | |
for member in members: | |
if member['username'] == userName: | |
MyCards.append(card) | |
break | |
newline = '\n' | |
MyTasks = [] | |
for card in MyCards: | |
cardNum = card['idShort'] | |
desc = card['desc'] | |
cardName = card['name'] | |
tasktitle = "Card #%s - %s" % (cardNum, cardName) | |
MyTasks.append(tasktitle) | |
if platform.system() == 'Darwin': | |
if platform.machine().startswith('iP'): | |
clipboard.set(newline.join(MyTasks)) | |
webbrowser.open('workflow://') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment