Last active
June 20, 2018 14:23
-
-
Save rungta/61e35095faf5e66e59e7 to your computer and use it in GitHub Desktop.
Render a Trello board’s contents from JSON into a more human readable format (Markdown).
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 -*- | |
""" | |
Render a Trello board's contents from JSON into a more human readable format (Markdown) | |
Sample output: | |
Board Name | |
========== | |
List Name | |
--------- | |
+ Card One | |
+ Card Two | |
- Checklist item | |
- Another checklist item | |
... | |
JSON exports are available under the board's `Menu > Share, Print and Export > Export JSON` | |
""" | |
import json | |
file = "board.json" | |
data = {} | |
with open(file) as f: | |
data = json.load(f) | |
lists_raw = data['lists'] | |
cards_raw = data['cards'] | |
checklists_raw = data['checklists'] | |
# create id based Hashes | |
cards = { c['id']: c for c in cards_raw } | |
lists = { l['id']: l for l in lists_raw } | |
# Nest checklists inside cards, and cards inside lists | |
for source, id_key, destination, collection_key in [ | |
(checklists_raw, 'idCard', cards, 'checklists'), | |
(cards_raw, 'idList', lists, 'cards'), | |
]: | |
for item in source: | |
target = destination[item[id_key]] | |
if not collection_key in target: | |
target[collection_key] = [] | |
target[collection_key].append(item) | |
# Filter out empty lists | |
lists_raw = filter(lambda l : 'cards' in l, lists_raw) | |
# Board name | |
if len(lists_raw): | |
print data['name'], "\n", '=' * len(data['name']), "\n\n" | |
# Lists -> Cards -> Checklist items | |
for tasklist in lists_raw: | |
print tasklist['name'], "\n", '-' * len(tasklist['name']) | |
for card in tasklist['cards']: | |
print '+', card['name'] | |
if 'checklists' in card: | |
for checklist in card['checklists']: | |
for item in checklist['checkItems']: | |
print " -", item['name'] | |
print "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment