Created
April 14, 2014 14:59
-
-
Save rochacon/10655871 to your computer and use it in GitHub Desktop.
Simple script to extract card status and metrics from Trello
This file contains hidden or 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 -*- | |
# Simple script to extract card info out of Trello | |
# | |
# ATTENTION: THIS IS TOO INCOMPLETE, but may be a base for something useful | |
# | |
# TODO: count points | |
# TODO: extra: count "blocks" per card | |
# | |
from multiprocessing import Pool | |
import requests | |
# Creating an API Key and Token | |
# For the key, access this URL: | |
# https://trello.com/1/appKey/generate | |
# For the token, access this: | |
# https://trello.com/1/authorize?response_type=token&expiration=30days&name=gui&key=REPLACE_WITH_YOUR_KEY | |
API_KEY = '' | |
API_TOKEN = '' | |
# Your Board ID | |
BOARD_ID = 'My Board' | |
# Cards to be looking for | |
# TODO make this dynamic | |
cards = { | |
# 'aabbccd', # Card ID example | |
} | |
def get_card(cid): | |
""" | |
Return a card JSON representation | |
""" | |
r = requests.get('https://trello.com/1/cards/%s' % cid , params={ | |
'key': API_KEY, 'token': API_TOKEN}) | |
if r.status_code != 200: | |
return None | |
return r.json() | |
def cards_by_list(lists): | |
""" | |
List cards grouped by list | |
""" | |
# get and map cards | |
p = Pool() | |
card_list = p.map(get_card, cards) | |
p.close() | |
p.join() | |
for card in card_list: | |
lists[card['idList']]['cards'].append(card) | |
# List cards | |
for lId, l in sorted(lists.items(), key=lambda l: l[1]['name']): | |
print 'List: %s' % l['name'] | |
for c in l['cards']: | |
print 'Name: %(name)s' % c | |
if __name__ == '__main__': | |
board = requests.get('https://trello.com/1/boards/%s' % BOARD_ID, params={'key': API_KEY, 'token': API_TOKEN}).json() | |
lists = requests.get('https://trello.com/1/boards/%s/lists' % BOARD_ID, params={'key': API_KEY, 'token': API_TOKEN}).json() | |
lists = {l['id']: l for l in lists} # {'idList': listJson} | |
for k, v in lists.items(): | |
v['cards'] = [] | |
cards_by_list(lists) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment