Permalink
Browse files

can write to the file c:\temp\hugo.txt calling write-to-file from the…

… REPL.
  • Loading branch information...
1 parent 84cea37 commit 69dcfc3864727d9885152d9ac10c3a24235acfd4 @rippinrobr committed Nov 11, 2011
Showing with 22 additions and 8 deletions.
  1. +5 −5 hugoclr.clj
  2. +13 −0 hugoclr/data/csv.clj
  3. +4 −3 hugoclr/parser.clj
View
@@ -4,13 +4,13 @@
(ns hugoclr
(:gen-class)
- (:use hugoclr.parser))
+ (:use hugoclr.parser)
+ (:use hugoclr.data.csv :as csv ))
(def base-url "http://www.thehugoawards.org/hugo-history/")
-(defn print-href-value [anchor]
- (.Value (first (.Attributes anchor))))
-
(defn -main [& args]
(println (str "base-url: " base-url))
- (hugoclr.parser/get-awards base-url))
+ (let [awards (hugoclr.parser/get-awards base-url)]
+ (csv/)
+
View
@@ -0,0 +1,13 @@
+(ns hugoclr.data.csv)
+
+(defn delimit
+ [year books]
+ (map #(str year "," (:winner %) "," (:title %) "," (:publisher %) "\r\n") books))
+
+(defn write-to-file
+ [categories file-name]
+ (let [stream (System.IO.StreamWriter. file-name)
+ lines (map #(delimit (:year (first %)) (:books (first %))) categories)]
+ (.Write stream (apply str (map #(reduce str "" %) lines)))
+ (.Close stream)))
+
View
@@ -68,13 +68,14 @@
[award-url]
;; this will get the author and publisher of the work: (.InnerHtml (first (.ChildNodes (second (.ChildNodes ul)))))
(let [top-node (get-html-elements award-url "//div[@id='content']/p[not(@class)][2]")]
- top-node))
- ;;(map create-category-struct top-node)))
+ ;; top-node))
+ (map create-category-struct top-node)))
(defn get-awards
"gets all the links from the http://www.thehugoawards.org/hugo-history/ that lead to a awards page"
[url]
(let [links (get-html-elements url "//li[@class]/a[@href]")
award-links (filter #(not (nil? %)) (map validate-award-link links))]
- award-links))
+ ;; award-links))
+ (map parse-awards-page (take 2 award-links))))

0 comments on commit 69dcfc3

Please sign in to comment.