Commits

Miki Tebeka committed 7dc448d

Loading all data

Comments (0)

Files changed (1)

 (ns clj2010
   (:require [apricot-soup :as soup])
   (:use [clj-time.core :only (hours minutes date-time plus)])
-  (:use [clojure.contrib.string :only (trim lower-case split)]))
+  (:use [clojure.contrib.string :only (trim lower-case split)])
+  (:import java.io.File))
 
 ; "chouser: " -> "chouser"
 (defn fix-user 
 (defn str->long [s]
   (Long/valueOf s))
 
+(def *date-re* #"(\d+)-(\d+)-(\d+)")
+
 (defn logfile-day [logfile]
-  (let [[match year month day] (re-find #"(\d+)-(\d+)-(\d+)" logfile)]
+  (let [[match year month day] (re-find *date-re* logfile)]
     (apply date-time (map str->long [year month day]))))
 
 (defn log-time [day hour minute]
         pp (partial process-p day)]
     (rest (reductions pp (cons nil (soup/$ (slurp logfile) p))))))
 
+(defn log-files [root]
+  (let [dir (File. root)
+        files (filter #(not (nil? (re-find *date-re* %))) (.list dir))]
+    (map #(str root "/" %) files)))
+
+(defn load-data [root]
+  (flatten (map process-logfile (log-files root))))
+
 (defn -main []
-  (dorun (map println (take 10 (process-logfile "logs/2010-01-01.html")))))
+  (dorun (map println (take 10 (load-data "logs")))))