Permalink
Browse files

commenting and cleaning

  • Loading branch information...
rippinrobr committed Nov 17, 2011
1 parent 8fb5d8b commit 8acac157453c33a0c081a88beb987a1359815d55
Showing with 17 additions and 1 deletion.
  1. +8 −1 src/hugoclr.clj
  2. +9 −0 src/hugoclr/data/csv.clj
View
@@ -1,13 +1,20 @@
+;;---------------------------------------------------------------------------
+;; hugoclr.clj
+;; The main function lives here. It simply calls the function to kick off
+;; the retrieval/parsing and writes the results to file system
+;;---------------------------------------------------------------------------
(assembly-load-from "..\\libs\\HtmlAgilityPack.dll")
(ns hugoclr
- (:gen-class)
+ (:gen-class) ;; generates the class and makes our exe. Without it
+ ;; only a dll is created.
(:use hugoclr.parser)
(:use hugoclr.data.csv))
(def base-url "http://www.thehugoawards.org/hugo-history/")
(defn -main [& args]
+ "runs the parser and writes the results to the hugo.txt file"
(println (str "base-url: " base-url))
(let [awards (hugoclr.parser/get-awards base-url)]
(hugoclr.data.csv/write-to-file awards "c:\\temp\\hugo.txt")))
View
@@ -1,17 +1,26 @@
+;;---------------------------------------------------------------------------
+;; csv.clj
+;; The code in this file is used to parse the HUGO award pages and create a
+;; a record for each nonimee/winner
+;;---------------------------------------------------------------------------
(ns hugoclr.data.csv)
(defn- clean
+ "Replaces commas with semi-colons, removes HTML tags, and converts vals to
+ their character representation using the .NET String.Replace method"
[val]
(.Replace (.Replace (.Replace (.Replace (.Replace val "," ";") "<em>" "") "</em>" "") "&#8217;" "'") "&amp;" "&"))
(defn- delimit
+ "Converts the works Record into a comma-delimited string."
[year books]
(map #(str year "," (:winner %) ","
(clean (:title %)) ","
(:author %) ","
(clean (:publisher %)) "\r\n") books))
(defn write-to-file
+ "writes the comma-delimited strings out to the path passed in in file-name."
[categories file-name]
(let [stream (System.IO.StreamWriter. file-name)
lines (map #(delimit (:year (first %)) (:books (first %))) categories)]

0 comments on commit 8acac15

Please sign in to comment.