Created
October 6, 2020 16:40
-
-
Save redblobgames/3d296e80a3622094e1c02d7653d30acb to your computer and use it in GitHub Desktop.
Output trello json to a hierarchical text file (org mode but could easily be markdown instead)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* | |
* I want to convert trello to a hierarchical text file (org mode) | |
* | |
* Trello can export to json. Save that json to a file. Then run this program. | |
*/ | |
/* | |
* Notes about format: | |
* | |
* cards have id: idList: name: idLabels: dateLastActivity: | |
* idChecklists: url: desc:(markdown format) closed: | |
* | |
* labels have id: name: color: closed: | |
* | |
* lists have id: name: | |
* | |
* where are comments? | |
* look under actions, {id: type:"commentCard", data: {card: {id:}, text:} | |
*/ | |
// TODO: use command line args for input & output filenames | |
const json = require('./redblobgames-2020.json'); | |
const util = require('util'); | |
const {execFileSync} = require('child_process'); | |
const OUT = (...args) => process.stdout.write(args.join('\n') + '\n'); | |
function formatDate(date) { | |
return `<${date.slice(0, 10)}>`; | |
} | |
function markdownToOrg(input) { | |
let output = execFileSync('pandoc', ['--from=markdown_strict-raw_html', '--to=org', '--columns=100000'], {input}); | |
output = output.toString() ?? ""; | |
output = output.trim(); | |
return output; | |
} | |
function output() { | |
OUT(`* ${json.name}`, | |
``); | |
for (let list of json.lists) { | |
OUT(`** ${list.name}`, | |
``); | |
for (let card of json.cards.filter(card => card.idList === list.id)) { | |
let labels = card.idLabels.map(id => json.labels.find(label => label.id === id)?.name).join(':'); | |
if (labels.length > 0) { labels = ` :${labels}:`; } | |
OUT(`*** ${card.name}${labels}`, | |
`${formatDate(card.dateLastActivity)}`, | |
``, | |
`${markdownToOrg(card.desc)}`); | |
for (let checklist of json.checklists.filter(checklist => checklist.idCard === card.id)) { | |
OUT(); | |
for (let item of checklist.checkItems) { | |
let marker = item.state === 'complete'? '[X]' : '[ ]'; | |
OUT(`- ${marker} ${markdownToOrg(item.name)}`); | |
} | |
} | |
for (let comment of json.actions.filter(action => action.type === "commentCard" && action.data.card.id === card.id)) { | |
OUT(``, | |
`**** comment from ${comment.memberCreator.username} ${formatDate(comment.date)}`, | |
`${markdownToOrg(comment.data.text)}`); | |
} | |
OUT(); | |
} | |
} | |
} | |
output(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment