2013-09-28 23:42:15 +02:00
|
|
|
(ns ldview.tasks.runner
|
|
|
|
(:require [ldview.tasks.scrape :as scrape]
|
|
|
|
[ldview.tasks.images :as images]
|
2013-09-30 00:37:38 +02:00
|
|
|
[me.raynes.fs :as fs]
|
|
|
|
[ldview.models.entry :as entry]
|
|
|
|
[ldview.models.competition :as competition]
|
2013-10-06 18:08:50 +02:00
|
|
|
[ldview.models.schema :as schema]))
|
2013-09-28 23:42:15 +02:00
|
|
|
|
2014-01-30 00:27:46 +01:00
|
|
|
;; 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! []
|
2013-10-06 18:08:50 +02:00
|
|
|
(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/")))
|
2013-09-28 23:42:15 +02:00
|
|
|
|
2014-01-30 00:27:46 +01:00
|
|
|
(defn save-entry! [new-entry]
|
2013-09-30 00:37:38 +02:00
|
|
|
(entry/create! new-entry)
|
|
|
|
(if (:images new-entry)
|
2013-09-28 23:42:15 +02:00
|
|
|
(map (fn [image-url]
|
2013-09-30 00:37:38 +02:00
|
|
|
(let [id (:ld_uid new-entry)
|
2013-09-28 23:42:15 +02:00
|
|
|
number (last (first (re-seq #"shot([0-9]+)" image-url)))
|
2013-09-30 00:37:38 +02:00
|
|
|
raw-image-path (images/image-name "raw" id number)]
|
2013-09-28 23:42:15 +02:00
|
|
|
(scrape/save-image-from-url image-url raw-image-path)
|
2013-09-30 00:37:38 +02:00
|
|
|
(images/sourceimage->fullscreen raw-image-path (images/image-name "fullscreen" id number))
|
|
|
|
(images/sourceimage->thumb raw-image-path (images/image-name "thumbs" id number))))
|
|
|
|
(:images new-entry))))
|
2013-09-28 23:42:15 +02:00
|
|
|
|
|
|
|
(defn fetch-all-content []
|
2013-09-30 00:37:38 +02:00
|
|
|
(let [pages (range 1)] ;(scrape/number-of-pages)]
|
|
|
|
(for [page pages]
|
|
|
|
(for [ld-uid (scrape/entries-on-page (inc page))]
|
|
|
|
(if-not (entry/exists? ld-uid)
|
|
|
|
(save-entry (scrape/entry-details ld-uid)))))))
|
2013-09-28 23:42:15 +02:00
|
|
|
|
2014-01-30 00:27:46 +01:00
|
|
|
(defn load-competition [id]
|
|
|
|
(swap! competition id)
|
|
|
|
(competition/create! id (scrape/theme))
|
2013-09-28 23:42:15 +02:00
|
|
|
(fetch-all-content))
|
|
|
|
|