Last active
August 1, 2019 19:24
-
-
Save calebhearth/7766e1b2d28c0482c517926f81c65c78 to your computer and use it in GitHub Desktop.
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
reading: | |
- title: Thief (Ratcatchers, #2) | |
author: Matthew Colville | |
url: https://www.goodreads.com/book/show/22236375-thief | |
- title: The Bear and the Nightingale (Winternight Trilogy, #1) | |
author: Katherine Arden | |
url: https://www.goodreads.com/book/show/25489134-the-bear-and-the-nightingale | |
- title: The Coming of Conan the Cimmerian (Conan the Cimmerian, #1) | |
author: Robert E. Howard | |
url: https://www.goodreads.com/book/show/33482.The_Coming_of_Conan_the_Cimmerian | |
read: | |
- title: "How to Draw Fantasy Art and RPG Maps: Step by Step Cartography for Gamers and Fans" | |
author: Jared Blando | |
url: https://www.goodreads.com/book/show/26107242-how-to-draw-fantasy-art-and-rpg-maps | |
- title: A Princess of Mars (Barsoom, #1) | |
author: Edgar Rice Burroughs | |
url: https://www.goodreads.com/book/show/15987725-a-princess-of-mars | |
- title: Brave New World | |
author: Aldous Huxley | |
url: https://www.goodreads.com/book/show/5129.Brave_New_World |
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
require "nokogiri" | |
require "jekyll" | |
require "net/http" | |
class Reading < Jekyll::Generator | |
DEFAULT_PARAMS = { | |
v: 2, | |
key: ENV.fetch("GOODREADS_KEY"), | |
sort: :date_updated, | |
id: ENV.fetch("GOODREADS_USER_ID"), | |
} | |
API_URL = URI('https://www.goodreads.com/review/list') | |
def generate(site) | |
reading = site.pages.detect {|page| page.name == 'reading.html'} | |
reading.data["read"] = download(shelf: 'reading', per_page: 3, sort: :date_read) | |
reading.data["reading"] = download(shelf: 'currently-reading') | |
end | |
def download(params) | |
uri = API_URL | |
uri.query = URI.encode_www_form(DEFAULT_PARAMS.merge(params)) | |
res = Net::HTTP.get_response(uri) | |
if !res.is_a?(Net::HTTPSuccess) | |
raise res.inspect | |
end | |
xml = Nokogiri::XML(res.body) | |
books = [] | |
xml.css('review').each do |book| | |
date_updated = book.at_css("date_updated").text | |
if !date_updated || Date.parse(book.at_css("date_updated").text) > Date.today - 42 # 6 weeks | |
books << { | |
'title' => book.at_css('title_without_series').text, | |
'author' => book.at_css('author name').text, | |
'url' => book.at_css('link').text, | |
} | |
end | |
end | |
books | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment