Skip to content

Instantly share code, notes, and snippets.

@founddrama
Created June 4, 2012 01:48
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 founddrama/2865829 to your computer and use it in GitHub Desktop.
Save founddrama/2865829 to your computer and use it in GitHub Desktop.
Get my 10 most popular reviews from Goodreads, using Clojure.
(def api-key "GET-YOUR-OWN")
(def url
(format "http://www.goodreads.com/review/list?v=2&key=%s&sort=votes&per_page=10&order=d&id=156533" api-key))
(defn extract-tag [tag coll]
(let [n (first coll)]
(if (= tag (:tag n))
(:content n)
(extract-tag tag (rest coll)))))
(def reviews (extract-tag :reviews
(:content (clojure.xml/parse url))))
(map (fn [i] (apply format "%s by %s (%s votes)" i))
(map (fn [r]
(let [book (extract-tag :book (:content r))]
[(apply str (extract-tag :title book))
(apply str (extract-tag :name (:content (first (extract-tag :authors book)))))
(apply str (extract-tag :votes (:content r)))]))
reviews))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment