From 06b298c3760757b2ad8c7ef76c8b4ad45aa4aafe Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Sun, 28 Sep 2014 16:43:29 +0200 Subject: [PATCH] Now we are getting somewhere ... scraping ahead --- project.clj | 1 + src/luduverse/core.clj | 2 +- src/luduverse/db.clj | 2 +- src/luduverse/handler.clj | 6 ++---- src/luduverse/{ld-images.clj => images.clj} | 2 +- src/luduverse/{db-models => models}/competition.clj | 2 +- src/luduverse/{db-models => models}/entry.clj | 8 ++++---- src/luduverse/{db-models => models}/source.clj | 2 +- src/luduverse/{db-models => models}/user.clj | 2 +- src/luduverse/{ld-scraper.clj => scraper.clj} | 10 +++++----- 10 files changed, 18 insertions(+), 19 deletions(-) rename src/luduverse/{ld-images.clj => images.clj} (99%) rename src/luduverse/{db-models => models}/competition.clj (93%) rename src/luduverse/{db-models => models}/entry.clj (83%) rename src/luduverse/{db-models => models}/source.clj (91%) rename src/luduverse/{db-models => models}/user.clj (93%) rename src/luduverse/{ld-scraper.clj => scraper.clj} (94%) diff --git a/project.clj b/project.clj index 8ba4a4f..7a8624c 100644 --- a/project.clj +++ b/project.clj @@ -19,6 +19,7 @@ :init luduverse.handler/init :destroy luduverse.handler/destroy :open-browser? false} + :aliases {"save-competition-30" ["run" "-m" "luduverse.scraper/save-competition" "30"]} :profiles {:production {:ring {:stacktrace? false}} :dev {:ring {:auto-reload? true :auto-refresh? true}}}) diff --git a/src/luduverse/core.clj b/src/luduverse/core.clj index dbaa57b..c529005 100644 --- a/src/luduverse/core.clj +++ b/src/luduverse/core.clj @@ -1,5 +1,5 @@ (ns luduverse.core - (:require [luduverse.ld-scraper :as scraper]) + (:require [luduverse.scraper :as scraper]) (:gen-class)) (def -main []) diff --git a/src/luduverse/db.clj b/src/luduverse/db.clj index d6be540..c89ec40 100644 --- a/src/luduverse/db.clj +++ b/src/luduverse/db.clj @@ -3,7 +3,7 @@ [korma.db :refer [defdb mysql]])) (defdb db (mysql {:db "luduverse" - :user "root" + :user "luduverse" :password "dev"})) (declare entities competitions users sources) diff --git a/src/luduverse/handler.clj b/src/luduverse/handler.clj index 37a5046..75fb457 100644 --- a/src/luduverse/handler.clj +++ b/src/luduverse/handler.clj @@ -3,16 +3,14 @@ [compojure.route :as route] [noir.util.middleware :as middleware] [luduverse.pages :as pages] - [luduverse.ld-images :as images])) + [luduverse.images :as images])) (defroutes core-routes (route/resources "/") (GET "/" [] (pages/front-page)) (route/not-found "404, sorry.")) -(defn init [] - ; Create the image resource path if it is missing - (if (not (fs/exists? (images/base-path))) (fs/mkdirs (images/base-path)))) +(defn init []) (defn destroy []) diff --git a/src/luduverse/ld-images.clj b/src/luduverse/images.clj similarity index 99% rename from src/luduverse/ld-images.clj rename to src/luduverse/images.clj index 8de4be1..c29989c 100644 --- a/src/luduverse/ld-images.clj +++ b/src/luduverse/images.clj @@ -1,4 +1,4 @@ -(ns luduverse.ld-images +(ns luduverse.images (:require [image-resizer.core :refer :all] [image-resizer.util :as utils] [image-resizer.format :refer :all] diff --git a/src/luduverse/db-models/competition.clj b/src/luduverse/models/competition.clj similarity index 93% rename from src/luduverse/db-models/competition.clj rename to src/luduverse/models/competition.clj index d9ba17e..c53f878 100644 --- a/src/luduverse/db-models/competition.clj +++ b/src/luduverse/models/competition.clj @@ -1,4 +1,4 @@ -(ns luduverse.db-models.competition +(ns luduverse.models.competition (:require [korma.core :refer :all] [luduverse.db :refer :all])) diff --git a/src/luduverse/db-models/entry.clj b/src/luduverse/models/entry.clj similarity index 83% rename from src/luduverse/db-models/entry.clj rename to src/luduverse/models/entry.clj index 3edf1f7..7033655 100644 --- a/src/luduverse/db-models/entry.clj +++ b/src/luduverse/models/entry.clj @@ -1,9 +1,9 @@ -(ns luduverse.db-models.entry +(ns luduverse.models.entry (:require [korma.core :refer :all] [luduverse.db :refer :all] - [luduverse.db-models.user :as user] - [luduverse.db-models.competition :as competition] - [luduverse.db-models.source :as source])) + [luduverse.models.user :as user] + [luduverse.models.competition :as competition] + [luduverse.models.source :as source])) (defn all [] (select entries)) diff --git a/src/luduverse/db-models/source.clj b/src/luduverse/models/source.clj similarity index 91% rename from src/luduverse/db-models/source.clj rename to src/luduverse/models/source.clj index e842604..9969e98 100644 --- a/src/luduverse/db-models/source.clj +++ b/src/luduverse/models/source.clj @@ -1,4 +1,4 @@ -(ns luduverse.db-models.source +(ns luduverse.models.source (:require [korma.core :refer :all] [luduverse.db :refer :all])) diff --git a/src/luduverse/db-models/user.clj b/src/luduverse/models/user.clj similarity index 93% rename from src/luduverse/db-models/user.clj rename to src/luduverse/models/user.clj index 5f25865..458ca1e 100644 --- a/src/luduverse/db-models/user.clj +++ b/src/luduverse/models/user.clj @@ -1,4 +1,4 @@ -(ns luduverse.db-models.user +(ns luduverse.models.user (:require [korma.core :refer :all] [luduverse.db :refer :all])) diff --git a/src/luduverse/ld-scraper.clj b/src/luduverse/scraper.clj similarity index 94% rename from src/luduverse/ld-scraper.clj rename to src/luduverse/scraper.clj index d85d90f..200a29b 100644 --- a/src/luduverse/ld-scraper.clj +++ b/src/luduverse/scraper.clj @@ -1,10 +1,10 @@ -(ns luduverse.ld-scraper +(ns luduverse.scraper (:require [net.cgrand.enlive-html :as html] [clojure.java.io :as io] [clojure.string :refer [split trim]] - [luduverse.ld-images :as image] - [luduverse.db-models.entry :as entry] - [luduverse.db-models.competition :as competition])) + [luduverse.images :as image] + [luduverse.models.entry :as entry] + [luduverse.models.competition :as competition])) ;; NOTE: This part is grabbed from the open source lib ;; https://github.com/arg-games/ldview @@ -72,7 +72,7 @@ and simply fetch it from Wikipedia. End of discussion :)" :images images})) -;; Save all what we got +;; Save what we got (defn save-entry [competition-id entry-id] (let [entry (entry-details competition-id entry-id)] (if-not (competition/exists? competition-id) (competition/create! competition-id (theme competition-id)))