Created
June 4, 2012 01:48
-
-
Save founddrama/2865829 to your computer and use it in GitHub Desktop.
Get my 10 most popular reviews from Goodreads, using Clojure.
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
(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