Skip to content

Instantly share code, notes, and snippets.

@maxcodes
Last active April 22, 2020 02:31
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 maxcodes/893805cd0bb5f97022f67ebc1b9a4e45 to your computer and use it in GitHub Desktop.
Save maxcodes/893805cd0bb5f97022f67ebc1b9a4e45 to your computer and use it in GitHub Desktop.
Import Goodreads Export into Roam
require "csv"
def roam_bookshelf(shelf)
case shelf
when "favorites"
"Favorite"
when "re-read"
"Re-Read"
when "bios"
"Biography"
else
shelf.upcase.tr("-", " ")
end
end
def goodreads_to_roam(shelf)
case shelf
when "currently-reading"
"[[READING]]"
when "read"
"[[READ]]"
when "to-read"
"[[TO READ]]"
end
end
def is_default_shelf?(shelf)
["read", "currently-reading", "to-read"].include? shelf
end
def step_by_step(bookshelves)
bookshelves = bookshelves&.split(", ")
return if bookshelves.nil? || bookshelves.empty?
bookshelves.reject! { |shelf| is_default_shelf?(shelf) }
bookshelves&.map! { |shelf| "#[[#{roam_bookshelf(shelf)}]]" }
end
templates = []
CSV.foreach("goodreads.csv", headers: true) do |row|
title = row["Title"]
author = row["Author"]
reading_status = goodreads_to_roam(row["Exclusive Shelf"])
shelves = step_by_step(row["Bookshelves"])
template = <<-BOOK
- [[#{title}]]
- Author:: [[#{author}]]
- Reading Status:: #{reading_status}
- Recommended By::
- Tags:: #Books #{shelves.join(", ") if shelves}
- :hiccup [:hr]
- ## Ideas
- ## Highlights
BOOK
templates << template
end
IO.popen('pbcopy', 'r+') { |clipboard| clipboard.puts templates.join("\n") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment