38 lines
1.2 KiB
Clojure
38 lines
1.2 KiB
Clojure
|
(ns ldview.tasks.runner
|
||
|
(:require [ldview.tasks.scrape :as scrape]
|
||
|
[ldview.tasks.images :as images]
|
||
|
[me.raynes.fs :as fs])
|
||
|
(:use [ldview.util]))
|
||
|
|
||
|
(defn cleanup []
|
||
|
(if (fs/exists? *image-base-path*)
|
||
|
(fs/delete-dir *image-base-path*))
|
||
|
(fs/mkdirs (str *image-base-path* "/thumbs/"))
|
||
|
(fs/mkdirs (str *image-base-path* "/fullscreen/"))
|
||
|
(fs/mkdirs (str *image-base-path* "/raw/")))
|
||
|
|
||
|
(defn save-entry [entry]
|
||
|
; TODO: Save to Database
|
||
|
(if (:images entry)
|
||
|
(map (fn [image-url]
|
||
|
(let [id (:id entry)
|
||
|
number (last (first (re-seq #"shot([0-9]+)" image-url)))
|
||
|
raw-image-path (images/image-name "raw" number)]
|
||
|
(scrape/save-image-from-url image-url raw-image-path)
|
||
|
(images/sourceimage->fullscreen raw-image-path (images/image-name "fullscreen" number))
|
||
|
(images/sourceimage->thumb raw-image-path (images/image-name "thumbs" number))))
|
||
|
(:images entry))))
|
||
|
|
||
|
; TODO: Make it multithreaded
|
||
|
(defn fetch-all-content []
|
||
|
(let [pages 1] ;(scrape/number-of-pages)]
|
||
|
(map (fn [page]
|
||
|
(map save-entry (scrape/fetch-page 1)))
|
||
|
(range pages))))
|
||
|
|
||
|
|
||
|
(defn start []
|
||
|
(cleanup)
|
||
|
(fetch-all-content))
|
||
|
|