diff src/rlm/kitchen_mailer.clj @ 0:78a630e650d2

initial import
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 00:57:08 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rlm/kitchen_mailer.clj	Tue Oct 18 00:57:08 2011 -0700
     1.3 @@ -0,0 +1,75 @@
     1.4 +":";exec java -cp $HOME/roBin/src:$HOME/roBin/lib/* clojure.main $0 $*; 
     1.5 +
     1.6 +(ns rlm.kitchen-mailer
     1.7 +  "This program runs every day as a cron job to remind people
     1.8 +   to clean the tetazoo kitchen.  Everyone with a cabinet must
     1.9 +   clean the kitchen."
    1.10 +  {:author "Robert McIntyre"}
    1.11 +  (:use [com.draines.postal [core :only [send-message]]]
    1.12 +	[rlm [shell-inspect :only [command-line?]]])
    1.13 +  (:import [org.joda.time Days DateMidnight]))
    1.14 +
    1.15 +(defn start-day [] (DateMidnight. 2011 2 13))
    1.16 +
    1.17 +(def cabinets
    1.18 +     [["deborahc"]
    1.19 +      ["maponte"]
    1.20 +      ["k_french"] 
    1.21 +      ["clarkds"]
    1.22 +      ["kharring"]
    1.23 +      ["jasminef"]
    1.24 +      ["kerrynic"]
    1.25 +      ["guertin"]
    1.26 +      ["ervanalb"]
    1.27 +      ["tayral13"]
    1.28 +      ["rbowru"]
    1.29 +      ["lexrj"]
    1.30 +      ["viccro"]
    1.31 +      ["kfish"]
    1.32 +      ["k8r" "infrared"]
    1.33 +      ["verdant"]
    1.34 +      ["greener"]
    1.35 +      ["phulin"]
    1.36 +      ["slehmann"]
    1.37 +      ["acrefoot"]
    1.38 +      ["oliviame"]])
    1.39 +
    1.40 +(def kitchen-reminder
    1.41 +  {:from "kitchen-bitch-bot@rlmcintyre.com"
    1.42 +   :cc [ "rlm@mit.edu"  "slehmann@mit.edu" ]
    1.43 +   :subject "It's your turn to clean the kitchen"
    1.44 +   :body  "
    1.45 +    It's your day to clean the kitchen.
    1.46 +    If it isn't clean by 23:00, I will not hesitate to
    1.47 +    hunt you down/wake you up/pry you away from your p-set.
    1.48 +
    1.49 +         <3, Kitchen Bitch
    1.50 +
    1.51 +    --------------------------------------------
    1.52 +    This mailer is open source and all that; you can see the source at
    1.53 +    http://www.rlmcintyre.com/kitchen-bitch.txt"})
    1.54 +     
    1.55 +(defn get-current-date []  (DateMidnight.))
    1.56 +
    1.57 +(defn days-since-start-day [start-day end-day]
    1.58 +  (.getDays (Days/daysBetween start-day end-day)))
    1.59 +
    1.60 +(defn mail-a-tetazoan
    1.61 +  "tetazoan will be a username like kfish, with the \"@mit.edu\" implied."
    1.62 +  [tetazoan message]
    1.63 +  (if-not (nil? tetazoan)
    1.64 +    (let [message (merge message {:to (into [] (map #(str % "@mit.edu") tetazoan))})]
    1.65 +      (println message)
    1.66 +      (send-message message))))
    1.67 +       
    1.68 +(defn target-person []
    1.69 +  (cabinets
    1.70 +   (rem (days-since-start-day (start-day) (get-current-date))
    1.71 +	(count cabinets))))
    1.72 +
    1.73 +(defn main []
    1.74 +  (println "mailing " (target-person)) 
    1.75 +;;  (println (mail-a-tetazoan (target-person) kitchen-reminder))
    1.76 +  )
    1.77 +
    1.78 +(if (command-line?) (main))