Skip to content

Instantly share code, notes, and snippets.

@Morpheu5
Last active August 29, 2015 14:05
Show Gist options
  • Save Morpheu5/5639bf3064ee808b67fd to your computer and use it in GitHub Desktop.
Save Morpheu5/5639bf3064ee808b67fd to your computer and use it in GitHub Desktop.
A thing that grabs a Trello board export in JSON and turns it into a rather badly formatted Markdown document.
#!/usr/bin/env ruby
require 'json_select'
require 'yajl'
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
opts.separator ''
opts.separator 'If an input file is not specified, stdin is used.'
opts.separator ''
opts.on('-i [filename]', "File containing JSON input") { |v| options[:input_filename] = v }
opts.on_tail("-h", "--help", "Show this message") { puts opts }
opts.on_tail("--version", "Show version") { puts '0.0.1' }
end.parse!
json = ""
if options[:input_filename]
json = File.new(options[:input_filename], 'r')
else
json = $<.read
end
parser = Yajl::Parser.new
hash = parser.parse(json)
lists = {}
list_ids = JSONSelect('array.lists').match(hash).each { |l| lists[l['id']] = l['name'] }
lists.keys.each do |lk|
puts '# ' + lists[lk]
cards = JSONSelect("array.cards").match(hash).reject { |c| c['idList'] != lk or c['name'] == '^' or c['closed'] }
cards.each { |c| puts "\n## " + c['name'] + "\n\n" + c['desc'] }
puts "\n\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment