From ddcfad7feae967e38b7ab5c959115ad8a4311e81 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Wed, 29 Jan 2014 23:58:44 +0100 Subject: [PATCH] Scrape the competition theme from the page --- src/ldview/tasks/scrape.clj | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ldview/tasks/scrape.clj b/src/ldview/tasks/scrape.clj index a13fe6a..451a72e 100644 --- a/src/ldview/tasks/scrape.clj +++ b/src/ldview/tasks/scrape.clj @@ -6,7 +6,7 @@ ; Some helper functions to construct proper urls. If the Ludum Date Website ; changes some URL stuff, this is the place to crank. -; TODO: make dynamic +; TODO: make this dynamic and replace all places in the code (def competition 27) (defn url-action [action] @@ -24,7 +24,6 @@ (defn fetch-url [url] (html/html-resource (java.net.URL. url))) -; TODO: bugfix missing images (probably) (defn save-image-from-url [url target-file] (with-open [bodystream (:body (http/get url {:as :stream}))] (io/copy bodystream (io/file target-file)))) @@ -41,6 +40,10 @@ links (map #(:href %1) (map #(:attrs (first (html/select [%1] [:a]))) tds))] (map #(last (split %1 #"=")) links))) +(defn competition-theme [competition] + (let [p (html/select (fetch-url (url-action "preview")) [:div#content :> :div.post :> :div.entry :> :p html/first-child :a])] + (first (:content (first p))))) + (defn links-on-entry [content] (map (fn [x] {:title (first (:content x)) :url (:href (:attrs x))}) (html/select [content] [:p.links :> :a]))) @@ -64,5 +67,3 @@ :type (format-entry-type unformatted-type) :links links :images images})) - -; TODO: check for -> scrape sources from game, too (WIN, MAC, LINUX,...)