Skip to content

Instantly share code, notes, and snippets.

@kjaymiller
Created October 14, 2015 14:44
Show Gist options
  • Save kjaymiller/430540966515e078437b to your computer and use it in GitHub Desktop.
Save kjaymiller/430540966515e078437b to your computer and use it in GitHub Desktop.
Takes the exported JSON
import json
with open('9E2fnCy5.json', 'r+') as f:
board = json.loads(f.read())
def trello_attrs():
print('Board Keys \n {} \n'.format(board.keys()))
print('Card Keys \n {} \n'.format(board['cards'][0].keys()))
input('Press Enter to Continue')
def create_toc(trello_list):
active_list = trello_list
print('There are {} cards \n'.format(len(trello_list)))
table_of_contents = []
while active_list:
x = 0
for list_card in active_list:
print('{} - {}'.format(x, list_card['name']))
x += 1
menu_length = len(active_list)
menu_selection = input('Select a Menu Item:')
if menu_selection != '':
selection = int(menu_selection)
print('{} Selected \n'.format(active_list[selection]['name']))
table_of_contents.append(active_list.pop(selection))
else:
break
return table_of_contents
def get_contents_description(table_of_contents, cards):
document_list = []
for card in table_of_contents:
title = toc_card['name']
data = [(c['name'], c['desc']) for c in cards if c['idList'] == card['id']]
data.insert(0, title)
document_list.append(data)
return document_list
def compile_contract(document_list):
document = ''
for section in document_list:
section_title = section[0]
document += '# {}\n'.format(section[0])
for sub in section:
if sub != section[0]:
document += '## {}\n'.format(sub[0])
document += '{}\n\n'.format(sub[1])
return document
trello_lists = [bl for bl in board['lists'] if not bl['closed']]
trello_cards = [c for c in board['cards'] if not c['closed']]
table_of_contents = create_toc(trello_lists)
content = get_contents_description(table_of_contents, trello_cards)
document = compile_contract(content)
with open('contract.txt', 'w+') as f:
f.write(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment