Skip to content

Instantly share code, notes, and snippets.

@paradox460
Created August 27, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paradox460/98b08d3d0d631e3cb60ec920475baa73 to your computer and use it in GitHub Desktop.
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
#! /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