Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for comments #2

Merged
merged 4 commits into from
Oct 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ MDPROC = pandoc
PANDOCTEMPLATE_TEX = tex/trello.latex
#$< is the first "source"
#$@ is the "target to generate"

# to add the table of contents add the following to MDPARAMS_PDF
# --variable=toc:1

# to get less margins add the following to MDPARAMS_PDF
# --variable=margin-left:2cm --variable=margin-right:2cm --variable=margin-top:2cm --variable=margin-bottom:2cm

MDPARAMS_PDF = $< -o $@ --template=`pwd`/$(PANDOCTEMPLATE_TEX)
MDPARAMS_HTML = $< -o $@
MDPARAMS_TEX = $< -o $@
Expand Down
44 changes: 38 additions & 6 deletions src/trello2md.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,41 @@ def prepare_content(content):
return '\n'.join(result)

################################################################################
def print_card(card_id, data, print_labels, print_card_links):
"""Print name, content and attachments of a card."""
def prepare_all_comments(data):
"""Returns a dictionary for each card_id with a list of comments"""
ret = {}

for action in data['actions']:
if action["type"] == "commentCard":
card_id = action["data"]["card"]["id"]

if not card_id in ret:
ret[card_id] = []

name = action["memberCreator"]["fullName"]
date = action["date"]
content = prepare_content(action["data"]["text"])

comment_string = "- **{name}** ({date}):\n {content} \n".format(
name=name, date=date, content=content)

ret[card_id].append(comment_string)
return ret

################################################################################
def print_card(card_id, data, comments, print_labels):
"""Print name, content, comments and attachments of a card."""

# get card and pre-format content
card = next(c for c in data['cards'] if c['id'] == card_id)
content = prepare_content(card['desc']) + '\n'

comment_output = ''
#comments are empty if they should not be printed
if card_id in comments:
comment_output = '### Comments ###\n'
comment_output += '\n\n'.join(comments[card_id])

# format labels, if wanted
labels = []
if print_labels and card['labels']:
Expand All @@ -69,10 +97,11 @@ def print_card(card_id, data, print_labels, print_card_links):
attachments_string = '\n\n'.join(attachments) + '\n'

# put it together
return '## {name} {lbls} ##\n{cntnt}\n{attms}\n'.format( \
return '## {name} {lbls} ##\n{cntnt}\n{attms}\n{comments}\n'.format( \
name=unlines(card['name']), \
cntnt=content, \
attms=attachments_string, \
comments=comment_output, \
lbls=labels_string)

################################################################################
Expand All @@ -97,6 +126,7 @@ def main():
parser = argparse.ArgumentParser(description='Convert a JSON export from Trello to Markdown.')
parser.add_argument('inputfile', help='Path to the input JSON file')
parser.add_argument('-i', '--header', help='Include header page', action='store_true')
parser.add_argument('-m', '--comments', help='Include card comments', action='store_true')
parser.add_argument('-l', '--labels', help='Print card labels', action='store_true')
parser.add_argument('-a', '--archived', help='Don\'t ignore archived lists', action='store_true')
parser.add_argument('-c', '--card-links', help='(Currently not implemented)', action='store_true')
Expand All @@ -120,7 +150,9 @@ def main():
markdown.append("Number of lists: {0} \n".format(len(data['lists'])))
markdown.append("Number of cards in lists: {0} \n".format(len(data['cards'])))
markdown.append("Last change: {0}\n\n\n".format(data['dateLastActivity']))

comments = {}
if args.comments:
comments = prepare_all_comments(data)
# process all lists in 'data', respecting closedness
for lst in data['lists']:
if not lst['closed'] or args.archived:
Expand All @@ -132,8 +164,8 @@ def main():
if (not card['closed'] or args.archived) and (card['idList'] == lst['id']):
markdown.append(print_card(card['id'], \
data, \
args.labels, \
args.card_links))
comments, \
args.labels))
markdown.append(print_checklists(card['id'], data))

# save result to file
Expand Down