/
newegg.clj
35 lines (28 loc) · 950 Bytes
/
newegg.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;requires tagsoup
(defn startparse-tagsoup [s ch]
(let [p (org.ccil.cowan.tagsoup.Parser.)]
(.setContentHandler p ch)
(.parse p s)))
(defn zip-soup [url]
(clojure.zip/xml-zip (clojure.xml/parse url startparse-tagsoup)))
(def wishlist-url "http://secure.newegg.com/WishList/PublicWishDetail.aspx?WishListNumber")
(defn wishlist [num]
(format "%s=%s" wishlist-url (str num)))
(defn pick [choices tag]
((comp first filter) #(= tag (:tag %)) choices))
(def wishlist-price
(comp #(BigDecimal. %)
(partial into-array Character/TYPE)
(partial filter (partial not= \,))
rest first :content last
(partial filter #(= "totalPrice" (-> % :attrs :class)))
(partial filter #(= :td (:tag %)))
(partial tree-seq map? (comp seq :content))
first
zip-soup
wishlist))
(comment
user=> (wishlist-price 8795214)
147.95M
user=>
)