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})))))
(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.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)
(fs/delete-dir images/base-path))
(fs/mkdirs (str images/base-path "/thumbs/"))
(fs/mkdirs (str images/base-path "/fullscreen/"))
(fs/mkdirs (str images/base-path "/raw/")))
(defn save-entry [new-entry]
(defn save-entry! [new-entry]
(entry/create! new-entry)
(if (:images new-entry)
(map (fn [image-url]
@ -32,9 +36,8 @@
(if-not (entry/exists? ld-uid)
(save-entry (scrape/entry-details ld-uid)))))))
; TODO: Watch out, the competition is set in the scrape .... refactor this ...
; TODO: Only create the competition if not allready exists
(defn load-competition [id title]
(competition/create! id title)
(defn load-competition [id]
(swap! competition id)
(competition/create! id (scrape/theme))
(fetch-all-content))

View File

@ -2,12 +2,8 @@
(:require [net.cgrand.enlive-html :as html]
[clj-http.client :as http]
[clojure.java.io :as io])
(:use [clojure.string :only (split)]))
; 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)
(:use [clojure.string :only (split)]
[ldview.tasks.runner :only (@competition)]))
(defn url-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))]
(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])]
(first (:content (first p)))))