Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Convert a Trello JSON export file to an Org file

View trello2org.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
#!/usr/bin/env python
 
# trello2org.py
#
# Convert a Trello JSON export file to an Org file.
#
# Export your Trello JSON and run this script on it. Useful for if you're
# migrating your data away to Trello and into Org. It's not particularly fancy,
# nor does it use all of Org's features. But it gets the job done.
#
# Copyright 2014, Noah Slater <nslater@apache.org>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice and this
# notice are preserved. This file is offered as-is, without any warranty.
 
import json
import sys
 
def convertToOrg(data):
yield "#+TITLE %s\n" % data["name"]
 
listNames = {}
for trelloList in data["lists"]:
listNames[trelloList["id"]] = trelloList["name"]
 
lists = {}
for listName in listNames.values():
lists[listName] = []
 
for card in data["cards"]:
listName = listNames[card["idList"]]
lists[listName].append(card)
 
checklists = {}
for trelloChecklist in data["checklists"]:
checklists[trelloChecklist["id"]] = trelloChecklist
 
comments = {}
for action in data["actions"]:
if action["type"] == "commentCard":
cardID = action["data"]["card"]["id"]
if cardID not in comments:
comments[cardID] = []
try:
name = action["memberCreator"]["fullName"]
except:
name = "[deleted account]"
comments[cardID].append(name + ": " + action["data"]["text"])
 
for listName in lists:
yield "* " + listName
for card in lists[listName]:
name = card["name"]
if card["closed"]:
name = "DONE %s" % name
else:
name = "TODO %s" % name
if card["labels"]:
labels = []
for label in card["labels"]:
if label["name"]:
labels.append(label["name"])
else:
labels.append(label["color"])
name += " (" + ", ".join(labels) + ")"
 
yield "** " + name
desc = "\n" + card["desc"]
desc = desc.replace("\n*", "\n *")
yield desc[1:]
 
if card["attachments"]:
yield "Attachments:"
yield ""
for attachment in card["attachments"]:
attachment["url"]
yield ""
 
if card["idChecklists"]:
for checklistID in card["idChecklists"]:
yield "Checklist:"
yield ""
checklist = checklists[checklistID]
for checkItem in checklist["checkItems"]:
if checkItem["state"] == "complete":
state = "[X]"
else:
state = "[ ]"
yield state + " " + checkItem["name"]
yield ""
 
if card["id"] in comments:
yield "Comments:"
yield ""
for comment in comments[card["id"]]:
yield comment.replace("\n*", "\n *")
yield ""
 
def main():
try: name = sys.argv[1]
except:
print("Usage: %s FILENAME" % sys.argv[0])
sys.exit(2)
 
with open(name) as f:
text = f.read()
data = json.loads(text)
for line in convertToOrg(data):
line = line.replace("\r", "\n")
print(line.encode("utf-8"))
 
if __name__ == "__main__":
main()

handy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.