Commits

Jeffrey Stoffers committed ebb4562

Initial Import

Comments (0)

Files changed (7)

+/target
+/lib
+/classes
+/checkouts
+pom.xml
+pom.xml.asc
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
+.lein-repl-history
+# hb-client
+
+A Clojure library designed to ... well, that part is up to you.
+
+## Usage
+
+FIXME
+
+## License
+
+Copyright © 2013 FIXME
+
+Distributed under the Eclipse Public License, the same as Clojure.
+# Introduction to hb-client
+
+TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
+(defproject hb-client "0.1.0-SNAPSHOT"
+  :description "FIXME: write description"
+  :url "http://example.com/FIXME"
+  :license {:name "Eclipse Public License"
+            :url "http://www.eclipse.org/legal/epl-v10.html"}
+  :dependencies [[org.clojure/clojure "1.4.0"]
+                 [clj-http "0.7.2"]
+                 [enlive "1.1.1"]
+                 [digest "1.3.0"]])

src/hb_client/.#core.clj

+necronian@x230.3587:1370507468

src/hb_client/core.clj

+(ns hb-client.core
+  (:require [clj-http.client :as client]
+            [net.cgrand.enlive-html :as html]
+            [digest :as digest]
+            [clojure.java.io :as io]))
+
+(def hb-login-url "https://www.humblebundle.com/login")
+(def hb-games-url "https://www.humblebundle.com/home")
+(def username "")
+(def password "")
+
+(def hb-dl-path "")
+
+(defn enlive-parse
+  [s]
+  (html/html-resource (java.io.StringReader. s)))
+
+(defn retrieve-games-page
+  []
+  (binding [clj-http.core/*cookie-store* (clj-http.cookies/cookie-store)]
+    (client/post hb-login-url
+                 {:form-params {:username username :password password}})
+    (client/get hb-games-url)))
+
+(defonce eh (enlive-parse (:body (retrieve-games-page))))
+
+(defonce rows (html/select eh [:div.row]))
+
+(defn parse-icn
+  [coll]
+  (get-in (first (html/select coll [:div.icn :img])) [:attrs :src]))
+
+(defn parse-title
+  [coll]
+  (html/text (first (html/select coll [:div.gameinfo :div.title :a]))))
+
+(defn parse-subtitle
+  [coll]
+  (html/text (first (html/select coll [:div.gameinfo :div.subtitle :a]))))
+
+(defn parse-dl-type
+  [coll]
+  (second (clojure.string/split (get-in coll [:attrs :class]) #" ")))
+
+(defn parse-dl-size
+  [coll]
+  (first (:content (first (html/select coll [:div.dlsize :span.mbs])))))
+
+(defn parse-dl-md5
+  [coll]
+  (apply str (rest (get-in (first (html/select coll [:div.dlsize :a.dlmd5])) [:attrs :href]))))
+
+(defn parse-dl-date
+  [coll]
+  (get-in (first (html/select coll [:div.dlsize :a.dldate])) [:attrs :data-timestamp]))
+
+(defn parse-dl-web
+  [coll]
+  (get-in (first (html/select coll [:div.flexbtn :a.a])) [:attrs :data-web]))
+
+(defn parse-dl-torrent
+  [coll]
+  (get-in (first (html/select coll [:div.flexbtn :a.a])) [:attrs :data-bt]))
+
+(defn parse-dl-title
+  [coll]
+  (html/text (first (html/select coll [:div.flexbtn :a.a]))))
+
+(defn parse-download
+  [rows]
+  (first (merge (map (fn [coll]
+                       {:size (parse-dl-size coll)
+                        :md5 (parse-dl-md5 coll)
+                        :web (parse-dl-web coll)
+                        :torrent (parse-dl-torrent coll)
+                        :title (parse-dl-title coll)
+                        :date (parse-dl-date coll)})
+                     (html/select rows [:div.download])))))
+
+(defn parse-downloads
+  [row]
+  (merge (map (fn [coll]
+                {:dl-type (parse-dl-type coll)
+                 :download (parse-download coll)})
+              (html/select row [:div.downloads]))))
+
+(defn parse-row
+  [rows]
+  (map
+   (fn [coll]
+     {:title (parse-title coll)
+      :subtitle (parse-subtitle coll)
+      :icon (parse-icn coll)
+      :downloads (parse-downloads coll)})
+   rows))
+
+(defn directory?
+  [f]
+  (.isDirectory f))
+
+(defn parse-downloaded-md5
+  []
+  (map (fn [f] {:file f :md5 (digest/md5 f)}) (filter (comp not directory?) (file-seq (io/file hb-dl-path)))))
+
+(defonce humble-data (parse-row rows))
+
+(defonce file-data (parse-downloaded-md5))
+
+(defn -main
+  []
+  (:body (retrieve-games-page)))

test/hb_client/core_test.clj

+(ns hb-client.core-test
+  (:use clojure.test
+        hb-client.core))
+
+(deftest a-test
+  (testing "FIXME, I fail."
+    (is (= 0 1))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.