Skip to content

Instantly share code, notes, and snippets.

@cjp
Created June 2, 2015 16:26
Show Gist options
  • Save cjp/8c917cb9ddbf77139d0b to your computer and use it in GitHub Desktop.
Save cjp/8c917cb9ddbf77139d0b to your computer and use it in GitHub Desktop.
Convert Trello JSON export into CSV summary
#!/usr/bin/env ruby
#
# trello-json2csv.rb - Convert Trello JSON export into CSV summary
#
# note: only includes first label and first member of each card
#
# Copyright (C) 2015 Christopher J. Pilkington https://github.com/cjp
# Licensed under The MIT License, http://opensource.org/licenses/MIT
#
require 'json'
require 'csv'
require 'tzinfo'
json = JSON.parse ARGF.read, symbolize_names: true
puts CSV.generate_line ["Category", "Label", "Name", "Due Date", "Assignee",
"Subtask", "Subtask Status"], {:force_quotes => true}
members = Hash.new
json[:members].each { |member| members[member[:id]] = member[:fullName] }
json[:lists].each { |list|
json[:cards].each { |card|
assignee = card[:idMembers].any? ? members[card[:idMembers][0]] : ""
label = card[:labels].any? ? card[:labels][0][:name] : ""
duedate = card[:badges][:due].nil? ? "" : Time.parse(card[:badges][:due]).strftime("%Y-%m-%d")
if card[:idList] == list[:id]
if card[:badges][:checkItems] > 0
json[:checklists].each { |check|
if card[:id] == check[:idCard]
check[:checkItems].each { |checkitem|
puts CSV.generate_line [list[:name], label, card[:name], duedate, assignee,
checkitem[:name], checkitem[:state]], {:force_quotes => true}
}
end
}
else
puts CSV.generate_line [list[:name], label, card[:name], duedate, assignee, "", ""], {:force_quotes => true}
end
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment