Last active
December 25, 2019 20:08
-
-
Save vinc/b843ce13d618ef481885d555ea0727de to your computer and use it in GitHub Desktop.
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 "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