Skip to content

Instantly share code, notes, and snippets.

@vinc
Last active December 25, 2019 20:08
Show Gist options
  • Save vinc/b843ce13d618ef481885d555ea0727de to your computer and use it in GitHub Desktop.
Save vinc/b843ce13d618ef481885d555ea0727de to your computer and use it in GitHub Desktop.
require "csv"
require "rainbow/refinement"
using Rainbow
headers = ["Book Id", "ISBN", "Title", "Author", "Date Read"]
CSV.open("output.csv", "wb") do |csv|
csv << headers
CSV.foreach(ARGV.shift, headers: true) do |row|
puts format("%s %s (%d/5) %s", row["Date Added"].cyan, row["Title"], row["My Rating"], row["Exclusive Shelf"].yellow)
if row["Exclusive Shelf"] == "read"
row["Date Read"] ||= row["Date Added"]
row["Date Read"] = row["Date Read"].tr("/", "-")
row["ISBN"] = row["ISBN"][2..-2]
csv << row.to_h.slice(*headers).values
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment