Added type field to entries and some TODO comments

This commit is contained in:
Ruben Müller 2014-01-03 18:00:14 +01:00
parent 25126030f7
commit 97f2bee7d8
5 changed files with 14 additions and 4 deletions

View file

@ -26,6 +26,7 @@
:ld_uid (:ld_uid fields) :ld_uid (:ld_uid fields)
:title (:title fields) :title (:title fields)
:description (:description fields) :description (:description fields)
:type (:type fields)
:user_id (:id username) :user_id (:id username)
:competition_id competition-id}))) :competition_id competition-id})))
(for [link (:links fields)] (for [link (:links fields)]

View file

@ -19,6 +19,7 @@
[:ld_uid "INTEGER"] [:ld_uid "INTEGER"]
[:title "VARCHAR(255)"] [:title "VARCHAR(255)"]
[:description "TEXT"] [:description "TEXT"]
[:type "VARCHAR(255)"]
[:user_id "INTEGER"] [:user_id "INTEGER"]
[:competition_id "INTEGER"]) [:competition_id "INTEGER"])

View file

@ -2,9 +2,9 @@
(:use korma.core (:use korma.core
[ldview.models.db])) [ldview.models.db]))
(defn create! [entry_id uri description] (defn create! [entry_id uri title]
(if (empty? (select sources (where {:entry_id entry_id :type description}))) ; (if (empty? (select sources (where {:entry_id entry_id :type title})))
(insert sources (values {:entry_id entry_id (insert sources (values {:entry_id entry_id
:uri uri :uri uri
:type description})))) :type title})));)

View file

@ -24,6 +24,7 @@
(images/sourceimage->fullscreen raw-image-path (images/image-name "fullscreen" id number)) (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/sourceimage->thumb raw-image-path (images/image-name "thumbs" id number))))
(:images new-entry)))) (:images new-entry))))
; TODO: save 'links' to 'sources' in DB
(defn fetch-all-content [] (defn fetch-all-content []
(let [pages (range 1)] ;(scrape/number-of-pages)] (let [pages (range 1)] ;(scrape/number-of-pages)]

View file

@ -6,6 +6,7 @@
; Some helper functions to construct proper urls. If the Ludum Date Website ; Some helper functions to construct proper urls. If the Ludum Date Website
; changes some URL stuff, this is the place to crank. ; changes some URL stuff, this is the place to crank.
; TODO: make dynamic
(def competition 27) (def competition 27)
(defn url-action [action] (defn url-action [action]
@ -23,6 +24,7 @@
(defn fetch-url [url] (defn fetch-url [url]
(html/html-resource (java.net.URL. url))) (html/html-resource (java.net.URL. url)))
; TODO: bugfix missing images (probably)
(defn save-image-from-url [url target-file] (defn save-image-from-url [url target-file]
(with-open [bodystream (:body (http/get url {:as :stream}))] (with-open [bodystream (:body (http/get url {:as :stream}))]
(io/copy bodystream (io/file target-file)))) (io/copy bodystream (io/file target-file))))
@ -45,10 +47,13 @@
(defn images-on-entry [content] (defn images-on-entry [content]
(map #(:href (:attrs %1)) (html/select [content] [:table html/first-child :a]))) (map #(:href (:attrs %1)) (html/select [content] [:table html/first-child :a])))
(defn format-entry-type [unformated-type]
(if (= unformated-type "Jam Entry") "jam" "compo"))
(defn entry-details [entry-id] (defn entry-details [entry-id]
(let [content (first (html/select (fetch-url (url-entry entry-id)) [:div#compo2])) (let [content (first (html/select (fetch-url (url-entry entry-id)) [:div#compo2]))
title-parts (first (html/texts (html/select [content] [:h3]))) title-parts (first (html/texts (html/select [content] [:h3])))
[title author] (split title-parts #" - ") [title author type] (split title-parts #" - ")
links (links-on-entry content) links (links-on-entry content)
description (html/text (nth (html/select [content] [:p]) 2)) description (html/text (nth (html/select [content] [:p]) 2))
images (images-on-entry content)] images (images-on-entry content)]
@ -56,6 +61,8 @@
:title title :title title
:description description :description description
:author author :author author
:type (format-entry-type type)
:links links :links links
:images images})) :images images}))
; TODO: check for -> scrape sources from game, too (WIN, MAC, LINUX,...)