Skip to content

Instantly share code, notes, and snippets.

@gremau
Forked from RealOrangeOne/README.md
Last active March 18, 2024 18:21
Show Gist options
  • Save gremau/290ab394c9bf2d6d03c18444ff60c225 to your computer and use it in GitHub Desktop.
Save gremau/290ab394c9bf2d6d03c18444ff60c225 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/gremau/290ab394c9bf2d6d03c18444ff60c225/raw/trello-parser.py -o /usr/local/bin/trelloparse && sudo chmod +x /usr/local/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 python3
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'],
# example of how to parse the name field...
#"study": c['name'].split()[1] if c['name'].split()[0]=='study' else '',
#"pkg": c['name'].split()[1] if c['name'].split()[0]=='pkg' else '',
"list": lists[c['idList']],
"url": c['shortUrl'],
"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.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment