Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
46 lines (40 sloc) 1.39 KB
(ns lyeberry.minuteman
(:use lyeberry.html-utils)
(:require [net.cgrand.enlive-html :as html]
[clj-http.client :as client]))
(defn is-header?
(not-empty (html/select row #{[:th]})))
(defn copies-from-book-node
(let [rows (html/select book-node #{ [:.itemTable :tr] })]
(for [row rows
:let [cells (html/select row #{ [:td] })]
:when (not (is-header? row)) ]
{:location (clojure.string/capitalize
(clojure.string/replace (text-of (nth cells 0)) #"/.*" ""))
:call_number (text-of (nth cells 1))
:status (text-of (nth cells 2))
:url "" })))
(defn extract-copies
(let [title (text-at book-node [:.dpBibTitle :span.title :a])
author (clojure.string/replace
(text-at book-node [:.dpBibTitle :span.title :.customSecondaryText])
"/ " "")
copies (copies-from-book-node book-node)]
(for [copy copies] (merge {:title title :author author} copy))))
(defn extract-books
(map extract-copies
(select-from-html-string page-html [:.searchResult]))))
(defn search-url
(url-encode-book book)
(defn copies
(extract-books (:body (client/get (search-url book)))))