# HG changeset patch # User Steve Losh # Date 1317691690 14400 # Node ID 89f24149ecd78f054cf7785d47604bb84771ec61 # Parent a77d48fb4f63ae2122bb16537a50b9566351050b Start a refresh loop. diff -r a77d48fb4f63 -r 89f24149ecd7 src/newseasons/itunes.clj --- a/src/newseasons/itunes.clj Mon Oct 03 20:47:22 2011 -0400 +++ b/src/newseasons/itunes.clj Mon Oct 03 21:28:10 2011 -0400 @@ -1,5 +1,6 @@ (ns newseasons.itunes (:require [clj-http.client :as client]) + (:use newseasons.utils) (:use [cheshire.core :only (parse-string)])) @@ -15,12 +16,16 @@ "attribute" "showTerm"})) -(defn itunes-lookup [field id] - ((parse-string (:body (client/get "http://itunes.apple.com/search" - {:query-params {field id}}))) +(defn itunes-lookup [field id entity] + ((parse-string (:body (client/get "http://itunes.apple.com/lookup" + {:query-params {field id + "entity" entity}}))) "results")) -(defn itunes-lookup-artist [id] - (first (itunes-lookup "id" id))) +(defn itunes-lookup-seasons [id] + (let [results (itunes-lookup "id" id "tvSeason")] + (last (sort-maps-by (filter #(% "collectionName") + results) + "releaseDate")))) diff -r a77d48fb4f63 -r 89f24149ecd7 src/newseasons/loops/refresh.clj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/newseasons/loops/refresh.clj Mon Oct 03 21:28:10 2011 -0400 @@ -0,0 +1,22 @@ +(ns newseasons.loops.refresh + (:require [newseasons.models.shows :as shows]) + (:require [newseasons.itunes :as itunes]) + ) + +(defn- refresh-show [id] + (println " refreshing" id) + (let [show (itunes/itunes-lookup-seasons id)] + (println show) + (println " ->" (show "artistName")) + (Thread/sleep 5000))) + +(defn- refresh [] + (println "Refreshing Shows") + (let [shows (shows/shows-get-to-check)] + (dorun (map refresh-show shows)))) + + +(defn main [& args] + (println "Starting Refresh Loop!") + (println) + (dorun (repeatedly refresh))) diff -r a77d48fb4f63 -r 89f24149ecd7 src/newseasons/models/shows.clj --- a/src/newseasons/models/shows.clj Mon Oct 03 20:47:22 2011 -0400 +++ b/src/newseasons/models/shows.clj Mon Oct 03 21:28:10 2011 -0400 @@ -50,6 +50,10 @@ (defn show-set-url! [id new-url] @(r [:hset (key-show id) "url" new-url])) -(defn show-add-to-checked! [id] + +(defn show-add-to-check! [id] @(r [:sadd "shows:to-check" id])) +(defn shows-get-to-check [] + @(r [:smembers "shows:to-check"])) + diff -r a77d48fb4f63 -r 89f24149ecd7 src/newseasons/views/main.clj --- a/src/newseasons/views/main.clj Mon Oct 03 20:47:22 2011 -0400 +++ b/src/newseasons/views/main.clj Mon Oct 03 21:28:10 2011 -0400 @@ -121,7 +121,7 @@ (defpage [:post "/add"] {:keys [artist-id]} (login-required (users/user-add-show! (sess/get :email) artist-id) - (shows/show-add-to-checked! artist-id) + (shows/show-add-to-check! artist-id) (flash! "Added a show to your list.") (resp/redirect "/")))