Skip to content

Instantly share code, notes, and snippets.

@lazypower
Created August 9, 2012 00:43
Show Gist options
  • Save lazypower/3299993 to your computer and use it in GitHub Desktop.
Save lazypower/3299993 to your computer and use it in GitHub Desktop.
Script to facilitate in exporting LightHouse tickets to CSV format for import elsewhere
require 'csv'
#Get a collection of all the directories contained in the CWD
directories = Dir.entries(Dir.pwd)
#iterate
directories.each do |dir|
#if its a directory, then traverse into it
if File.directory?(dir) then
puts File.directory?(dir)
Dir.chdir(dir)
#find the json export - we dont need to bother with the misformatted CSV
if File.exists?('ticket.json') then
#read contents
file = File.open('ticket.json')
contents = file.read
#create an array to dump into a CSV file
content = contents['ticket']['assigned'] << '|' << contents['ticket']['title'] << '|' << contents['ticket']['updated_at'] << '|' << contents['ticket']['body']
#Traverse back to ^1 parent, and dump contents into a CSV
File.open("../../tickets.csv", 'a+') { |f| f.write(content << "\n") }
end
Dir.chdir("../")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment