Skip to content

Instantly share code, notes, and snippets.

@anjiro
Last active August 29, 2015 14:26
Show Gist options
  • Save anjiro/eb1d46b7668f74287429 to your computer and use it in GitHub Desktop.
Save anjiro/eb1d46b7668f74287429 to your computer and use it in GitHub Desktop.
Quick and dirty conversion of a Trello JSON export to an HTML outline
import json, codecs, mistune
from collections import defaultdict
def trello_json_to_html(jsonfile, outfile):
markdown = mistune.Markdown()
trello = json.load(open(jsonfile))
cards = defaultdict(list)
for card in trello['cards']:
cards[card['idList']].append(card)
hf = codecs.open(outfile, 'w', 'utf-8')
hf.write('<html>\n<head><meta charset="utf-8"></head>\n<body>\n<ul>')
for lst in trello['lists']:
hf.write('<li>%s\n<ul>\n' % lst['name'])
for card in cards[lst['id']]:
hf.write('<li>%s' % card['name'])
if card['desc']:
hf.write('\n<div>%s</div>\n</li>' %
markdown(card['desc']))
else:
hf.write('</li>\n')
hf.write('</ul>\n</li>\n')
hf.write('</ul>\n</body>\n</html>')
if __name__ == "__main__":
import sys
if len(sys.argv[1:]) < 2:
print "Usage: %s input_json output_html" % sys.argv[0]
sys.exit(0)
trello_json_to_html(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment