Skip to content

Instantly share code, notes, and snippets.

@RealOrangeOne
Last active August 31, 2024 19:53
Show Gist options
  • Save RealOrangeOne/c35751ee794e90df512bdfba6f22574d to your computer and use it in GitHub Desktop.
Save RealOrangeOne/c35751ee794e90df512bdfba6f22574d to your computer and use it in GitHub Desktop.
Trello JSON parser

Trello Parser

Download

Open a terminal, run this:

sudo curl https://gist.githubusercontent.com/RealOrangeOne/c35751ee794e90df512bdfba6f22574d/raw/trello-parser.py -o /usr/bin/trelloparse && sudo chmod +x /usr/bin/trelloparse

Usage

$ trelloparse -h
usage: tp [-h] input output

positional arguments:
  input       JSON File from Trello
  output      File to output to

optional arguments:
  -h, --help  show this help message and exit

Example

$ trelloparse ZRwW5Yyn.json output.json

CSV

To get the output in CSV format, use https://json-csv.com/

#!/usr/bin/env python2
import json
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("input", help="JSON File from Trello", type=str)
parser.add_argument("output", help="File to output to", type=str)
parser.add_help = True
args = parser.parse_args()
print "Reading Data..."
with open(os.path.abspath(args.input)) as f:
data = json.load(f)
print "Found {} cards in {} lists.".format(len(data['cards']), len(data['lists']))
print "Parsing..."
lists = {l['id']: l['name'] for l in data['lists']}
users = {u['id']: u['fullName'] for u in data['members']}
labels = {l['id']: l['name'] for l in data['labels']}
parsed_cards = [{
"name": c['name'],
"list": lists[c['idList']],
"description": c['desc'],
"members": [u for k, u in users.items() if k in c['idMembers']],
"labels": [l for k, l in labels.items() if k in c['idLabels']]
} for c in data['cards']]
output = {
"board_data": {
"name": data['name'],
"url": data['shortUrl']
},
"cards": parsed_cards
}
with open(os.path.abspath(args.output), 'w') as f:
json.dump(output, f, indent=4)
print "Output to {}!s".format(os.path.abspath(args.output))
print "Please visit https://json-csv.com/ to convert the output to CSV."
@ritchiew
Copy link

ritchiew commented Jun 4, 2024

This parser is not keeping the due date in the exported file. Can this be updated? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment