Created
August 27, 2016 23:00
-
-
Save paradox460/98b08d3d0d631e3cb60ec920475baa73 to your computer and use it in GitHub Desktop.
Little script for formatting Google Takeout JSON book lists into Goodreads compatible CSVs
This file contains 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
#! /usr/bin/env ruby | |
require 'json' | |
require 'csv' | |
files = Dir.glob('**/*.json') | |
CSV.open('googleplay.csv', 'wb') do |csv| | |
csv << ['ISBN', 'Date Read', 'Bookshelves'] | |
files.each do |f| | |
begin | |
x = JSON.load(IO.read(f).gsub(/\[\]\z/,''), :quirks_mode => true) | |
row = [] | |
isbn = x.dig('volumeInfo','industryIdentifiers')&.first&.dig('identifier') | |
next if isbn.nil? | |
row << isbn | |
row << DateTime.parse(x.dig('userInfo', 'acquiredTime')).strftime('%F') | |
row << 'google-play read' | |
csv << row | |
rescue StandardError | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment