Start refactoring the competiton

This commit is contained in:
Aaron Mueller 2014-01-30 00:27:46 +01:00
parent ddcfad7fea
commit 03ec7844e0
3 changed files with 15 additions and 14 deletions

View file

@ -14,4 +14,6 @@
(where {:number number}))))) (where {:number number})))))
(defn create! [number motto] (defn create! [number motto]
(insert competitions (values {:number number :motto motto}))) (if-not (exists? number)
(insert competitions (values {:number number
:motto motto}))))

View file

@ -6,14 +6,18 @@
[ldview.models.competition :as competition] [ldview.models.competition :as competition]
[ldview.models.schema :as schema])) [ldview.models.schema :as schema]))
(defn cleanup [] ;; TODO: This is ugly and not the right way to do. This should be cleaned up
;; so the functions does not have side effects
(def competition (atom 0))
(defn cleanup! []
(if (fs/exists? images/base-path) (if (fs/exists? images/base-path)
(fs/delete-dir images/base-path)) (fs/delete-dir images/base-path))
(fs/mkdirs (str images/base-path "/thumbs/")) (fs/mkdirs (str images/base-path "/thumbs/"))
(fs/mkdirs (str images/base-path "/fullscreen/")) (fs/mkdirs (str images/base-path "/fullscreen/"))
(fs/mkdirs (str images/base-path "/raw/"))) (fs/mkdirs (str images/base-path "/raw/")))
(defn save-entry [new-entry] (defn save-entry! [new-entry]
(entry/create! new-entry) (entry/create! new-entry)
(if (:images new-entry) (if (:images new-entry)
(map (fn [image-url] (map (fn [image-url]
@ -32,9 +36,8 @@
(if-not (entry/exists? ld-uid) (if-not (entry/exists? ld-uid)
(save-entry (scrape/entry-details ld-uid))))))) (save-entry (scrape/entry-details ld-uid)))))))
; TODO: Watch out, the competition is set in the scrape .... refactor this ... (defn load-competition [id]
; TODO: Only create the competition if not allready exists (swap! competition id)
(defn load-competition [id title] (competition/create! id (scrape/theme))
(competition/create! id title)
(fetch-all-content)) (fetch-all-content))

View file

@ -2,12 +2,8 @@
(:require [net.cgrand.enlive-html :as html] (:require [net.cgrand.enlive-html :as html]
[clj-http.client :as http] [clj-http.client :as http]
[clojure.java.io :as io]) [clojure.java.io :as io])
(:use [clojure.string :only (split)])) (:use [clojure.string :only (split)]
[ldview.tasks.runner :only (@competition)]))
; Some helper functions to construct proper urls. If the Ludum Date Website
; changes some URL stuff, this is the place to crank.
; TODO: make this dynamic and replace all places in the code
(def competition 27)
(defn url-action [action] (defn url-action [action]
(str "http://www.ludumdare.com/compo/ludum-dare-" competition "/?action=" action)) (str "http://www.ludumdare.com/compo/ludum-dare-" competition "/?action=" action))
@ -40,7 +36,7 @@
links (map #(:href %1) (map #(:attrs (first (html/select [%1] [:a]))) tds))] links (map #(:href %1) (map #(:attrs (first (html/select [%1] [:a]))) tds))]
(map #(last (split %1 #"=")) links))) (map #(last (split %1 #"=")) links)))
(defn competition-theme [competition] (defn theme []
(let [p (html/select (fetch-url (url-action "preview")) [:div#content :> :div.post :> :div.entry :> :p html/first-child :a])] (let [p (html/select (fetch-url (url-action "preview")) [:div#content :> :div.post :> :div.entry :> :p html/first-child :a])]
(first (:content (first p))))) (first (:content (first p)))))