From 623874aeca258e5a56910175ab3f3fa2c9f5f328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=BCller?= Date: Mon, 17 Oct 2016 22:42:37 +0200 Subject: [PATCH 1/4] support for comments --- src/trello2md.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/trello2md.py b/src/trello2md.py index faba1f2..001d06b 100755 --- a/src/trello2md.py +++ b/src/trello2md.py @@ -40,13 +40,39 @@ def prepare_content(content): return '\n'.join(result) ################################################################################ -def print_card(card_id, data, print_labels, print_card_links): +def prepare_comments(actions, card_id): + ret = [] + for action in actions: + try: + if action["type"] == "commentCard" and action["data"]["card"]["id"] == card_id: + comment = action["date"] + " \n" + comment += action["memberCreator"]["fullName"] + " \n" + comment += prepare_content(action["data"]["text"]) + ret.append(comment) + except: + pass + + if len(ret) > 0: + return "\n\n".join(ret) + else: + return "" + +################################################################################ +def print_card(card_id, data, print_labels, print_comments): """Print name, content 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' + if print_comments: + comments = prepare_comments(data['actions'], card_id) + else: + comments = "" + + #when none found or not selected for output + if len(comments) > 0: + comments = "### Comments ###\n" + comments # format labels, if wanted labels = [] if print_labels and card['labels']: @@ -69,10 +95,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=comments, \ lbls=labels_string) ################################################################################ @@ -97,6 +124,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') @@ -133,7 +161,7 @@ def main(): markdown.append(print_card(card['id'], \ data, \ args.labels, \ - args.card_links)) + args.comments )) markdown.append(print_checklists(card['id'], data)) # save result to file From d1f734f92cd3d6ad73c1e9b398f9dd169bf3d2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=BCller?= Date: Mon, 17 Oct 2016 23:11:26 +0200 Subject: [PATCH 2/4] some hints for pdf generation --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index f8329cf..af96796 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ From d3f1955808d48aa04266434083095e8e58c4f742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=BCller?= Date: Tue, 18 Oct 2016 21:51:32 +0200 Subject: [PATCH 3/4] faster extraction of comments --- src/trello2md.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/trello2md.py b/src/trello2md.py index 001d06b..a448489 100755 --- a/src/trello2md.py +++ b/src/trello2md.py @@ -40,39 +40,37 @@ def prepare_content(content): return '\n'.join(result) ################################################################################ -def prepare_comments(actions, card_id): - ret = [] - for action in actions: +def prepare_all_comments(data): + """Returns a dictionary for each card_id with a list of comments""" + ret = {} + for action in data['actions']: try: - if action["type"] == "commentCard" and action["data"]["card"]["id"] == card_id: + if action["type"] == "commentCard": + card_id = action["data"]["card"]["id"] + if not card_id in ret: + ret[card_id] = [] comment = action["date"] + " \n" comment += action["memberCreator"]["fullName"] + " \n" comment += prepare_content(action["data"]["text"]) - ret.append(comment) + ret[card_id].append(comment) except: pass - - if len(ret) > 0: - return "\n\n".join(ret) - else: - return "" + return ret ################################################################################ -def print_card(card_id, data, print_labels, print_comments): - """Print name, content and attachments of a card.""" +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' - if print_comments: - comments = prepare_comments(data['actions'], card_id) - else: - comments = "" + 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]) - #when none found or not selected for output - if len(comments) > 0: - comments = "### Comments ###\n" + comments # format labels, if wanted labels = [] if print_labels and card['labels']: @@ -99,7 +97,7 @@ def print_card(card_id, data, print_labels, print_comments): name=unlines(card['name']), \ cntnt=content, \ attms=attachments_string, \ - comments=comments, \ + comments=comment_output, \ lbls=labels_string) ################################################################################ @@ -148,7 +146,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: @@ -160,8 +160,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.comments )) + comments, \ + args.labels)) markdown.append(print_checklists(card['id'], data)) # save result to file From 4a6b9d99dbdf3ef888277f583776d5c8261713b2 Mon Sep 17 00:00:00 2001 From: Philipp Gabler Date: Fri, 21 Oct 2016 21:10:11 +0200 Subject: [PATCH 4/4] Format comments as markdown lists with name and date prepended --- src/trello2md.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/trello2md.py b/src/trello2md.py index a448489..211a0f6 100755 --- a/src/trello2md.py +++ b/src/trello2md.py @@ -43,18 +43,22 @@ def prepare_content(content): def prepare_all_comments(data): """Returns a dictionary for each card_id with a list of comments""" ret = {} + for action in data['actions']: - try: - if action["type"] == "commentCard": - card_id = action["data"]["card"]["id"] - if not card_id in ret: - ret[card_id] = [] - comment = action["date"] + " \n" - comment += action["memberCreator"]["fullName"] + " \n" - comment += prepare_content(action["data"]["text"]) - ret[card_id].append(comment) - except: - pass + 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 ################################################################################ @@ -65,11 +69,11 @@ def print_card(card_id, data, comments, print_labels): card = next(c for c in data['cards'] if c['id'] == card_id) content = prepare_content(card['desc']) + '\n' - comment_output = "" + 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]) + comment_output = '### Comments ###\n' + comment_output += '\n\n'.join(comments[card_id]) # format labels, if wanted labels = []