a7d0d997f520

Add emailing.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 05 Oct 2011 22:05:24 -0400
parents 9a3a49acb6e0
children 279de613dd93
branches/tags (none)
files src/newseasons/loops/refresh.clj

Changes

--- a/src/newseasons/loops/refresh.clj	Wed Oct 05 21:54:22 2011 -0400
+++ b/src/newseasons/loops/refresh.clj	Wed Oct 05 22:05:24 2011 -0400
@@ -1,8 +1,11 @@
 (ns newseasons.loops.refresh
+  (:use [postmark.core :only (postmark)])
+  (:use [newseasons.loops.templates.email :only (new-season)])
   (:use [newseasons.settings :only (postmark-api-key)])
   (:require [newseasons.models.shows :as shows])
   (:require [newseasons.itunes :as itunes]))
 
+(def pm (postmark postmark-api-key "newseasons@stevelosh.com"))
 
 ; Dammit, Clojure.
 (defn- gt [a b]
@@ -13,9 +16,13 @@
 
 
 (defn- notify [show email]
-  (println "    to:" email)
-  (println "        Sweet, a new season of" (:title show) "has been released!")
-  (println "        New season:" (:latest show)))
+  (let [body (new-season email show)]
+    (println (pm {:to email
+                  :subject (str "[New Seasons] A new season of "
+                                (:title show)
+                                " has hit iTunes!")
+                  :text body
+                  :tag "newseasons"}))))
 
 (defn- notify-all [show-id]
   (let [show (shows/show-get show-id)
@@ -34,13 +41,10 @@
 (defn- refresh-show [id]
   (println "  refreshing" id)
   (let [show (itunes/itunes-lookup-seasons id)]
-    (if show
-      (do
-        (check-and-notify show)
-        (shows/store-raw-show show)
-        (println (show "artistName") "/" (show "collectionName")))
-      (println "(unknown)"))
-    (Thread/sleep 4000)))
+    (when show
+      (check-and-notify show)
+      (shows/store-raw-show show))
+    (Thread/sleep 10000)))
 
 (defn- refresh []
   (println "")