Skip to content

Commit

Permalink
Write sunrise-sunset script in Clojure
Browse files Browse the repository at this point in the history
  • Loading branch information
wagdav committed Nov 21, 2024
1 parent bc3110b commit fa82abd
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scripts/push-sunrise-sunset.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bb
(require '[babashka.process :refer [shell process exec]]
'[org.httpkit.client :as hk-client])

(def NTFY_ADDRESS "http://nuc:8080/home-thewagner-ec1")
(def LAT "46.519833N")
(def LON "6.6335E")

(defn poll! []
(-> (shell {:continue true :out :string} "sunwait poll" LAT LON)
:out
str/split-lines
first))

(defn twilights! []
(-> (shell {:out :string} "sunwait list" LAT LON)
:out
str/split-lines
first))

(defn wait! []
(shell "sunwait wait" LAT LON))

(let [now (poll!)
lst (twilights!)
opts (merge
{:next-twilights lst}
(case now
"NIGHT" {:title "Sunrise!" :message "Good morning! 🌅"}
"DAY" {:title "Sunset!" :message "Good evening! 🌇"}))]
(println opts)
(try
(wait!)
@(hk-client/post NTFY_ADDRESS {:headers {"Title" (opts :title)}
:body (opts :message)})
(catch Exception e
(if (= 130 (:exit (ex-data e)))
(println "Interrupted")
(println "An Error occured" e)))))

0 comments on commit fa82abd

Please sign in to comment.