Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Created September 8, 2015 01:56
Show Gist options
  • Save jdjkelly/d3bd76eb539477f6be17 to your computer and use it in GitHub Desktop.
Save jdjkelly/d3bd76eb539477f6be17 to your computer and use it in GitHub Desktop.
Kindle Highlights -> Jekll Collection
require 'kindle_highlights'
require 'active_support/inflector'
kindle = KindleHighlights::Client.new(ARGV[0], ARGV[1])
books = kindle.books
bsins = books.keys.select { |key| books[key] =~ Regexp.new(ARGV[2], 'i') }
bsins.each {|bsin| puts "#{bsin} #{books[bsin]}\n" }
puts "\nChoose a BSIN:"
bsin = $stdin.gets.chomp
book = books[bsin]
highlights = kindle.highlights_for(bsin).sort! {|a,b| a['startLocation'] <=> b['startLocation'] }.map {|highlight| highlight['highlight']}
filename = ActiveSupport::Inflector.underscore(book).titleize.tr('^A-Za-z0-9', '').underscore.dasherize
File.open("_book-reviews/#{filename}.md", 'w') do |file|
file.write("---\nlayout: post\ntitle: \"#{book}\"\n---\n\n")
highlights.each do |highlight|
file.write("> #{highlight}\n\n")
end
file.close
end
system( "vim _book-reviews/#{filename}.md" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment