Created
March 5, 2013 02:33
-
-
Save juven/5087539 to your computer and use it in GitHub Desktop.
export your data in Trello and use this script to covert the exported json to xls
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
require 'json' | |
require 'spreadsheet' | |
if ARGV.size < 2 | |
puts 'Usage: ruby trello_to_csv.rb input.json output.xls' | |
exit 1 | |
end | |
@json_file = ARGV[0] | |
@xls_file = ARGV[1] | |
class Record | |
attr_accessor :date,:description | |
def initialize(date, description) | |
@date = date | |
@description = description | |
end | |
end | |
def parse_records(raw) | |
result = [] | |
dates = raw.sub(/^[^#]*#/, '') | |
description = raw.sub(/#.*$/, '') | |
dates.split('#').each do |date| | |
result << Record.new(date.strip, description.strip) | |
end | |
result | |
end | |
json = JSON.parse(File.read(@json_file)) | |
records = [] | |
result_records = [] | |
json['cards'].each do |card| | |
name = card['name'] | |
records += parse_records(name) | |
end | |
records.sort! do |x,y| | |
x.date <=> y.date | |
end | |
records.each do |record| | |
puts "#{record.date},#{record.description}" | |
result_records << record if result_records.size == 0 | |
if result_records[-1].date == record.date | |
result_records[-1].description += ("; " + record.description) | |
else | |
result_records << record | |
end | |
end | |
## Convert to xls file | |
book = Spreadsheet::Workbook.new | |
sheet = book.create_worksheet | |
header_format = Spreadsheet::Format.new( | |
:weight => :bold | |
) | |
sheet.row(0).default_format = header_format | |
sheet.row(0).replace(['Date', 'Description']) | |
result_records.each_index do |i| | |
row = [] | |
row << result_records[i].date << result_records[i].description | |
sheet.row(i+1).replace(row) | |
end | |
book.write(@xls_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment