~pepe/andy

c1ad2b6be4ad57c48a7748cb0f166f88396db31b — Josef Pospíšil 2 years ago b024f47
Move to shriek, remove ntb
3 files changed, 21 insertions(+), 20 deletions(-)

M andy.janet
M andy/weather.janet
M project.janet
M andy.janet => andy.janet +4 -12
@@ 11,26 11,18 @@
  (default file "conf.jdn")
  (def file-conf (parse (slurp file)))
  (default env "prod")
  (def config (file-conf (keyword env)))
  (def ntb (file-conf :ntb))
  (def neil-config (file-conf (keyword env)))
  (setdyn :psk (file-conf :psk))
  (setdyn :url (config :rpc))
  (setdyn :url (neil-config :rpc))
  (ev/spawn
    (weather/run (config/get "place") (config/get "wmp"))
    (timestamp/run)
    (servers/run (config/get "servers"))
    (task/run)
    (system/run (config/get "dev"))
    (when ntb
      (battery/run)
      (light/run))
    (forever
      (printf
        ;(if ntb
           ["%s %s %s %s %s %s %s"
            task/out weather/out battery/out light/out system/out
            timestamp/out servers/out]
           ["%s %s %s %s %s"
            task/out weather/out system/out timestamp/out servers/out]))
        "%s %s %s %s %s"
        task/out weather/out system/out timestamp/out servers/out)
      (flush)
      (ev/sleep 1))))

M andy/weather.janet => andy/weather.janet +14 -7
@@ 1,4 1,4 @@
(import http)
(import shriek)
(import json)

(var out "Connecting")


@@ 15,15 15,22 @@
    "\ue30c"))

(defn run [place wmp]
  (def url (string "api.openweathermap.org/data/2.5/weather?q=" place
                   "&units=metric&appid=" wmp))
  (shriek/global-init)
  (def curl (shriek/init))
  (def b @"")
  (:setopt curl :url (string "api.openweathermap.org/data/2.5/weather?q=" place
                             "&units=metric&appid=" wmp)
           :write-function (fn [buf] (buffer/push b buf)))
  (ev/spawn
    (forever
      (match (protect (-> url http/get (get :body) json/decode))
        [true (t (table? t))]
        (let [{"weather" [{"id" c} _]
      (match (protect (-> curl :perform))
        [true _]
        (let [t (json/decode b)
              {"weather" [{"id" c} _]
               "main" {"feels_like" f "temp" t "humidity" h "pressure" p}} t]
          (set out
               (string/format "%s %.1f °C %.1f °C %i%% %i hPa" (icon c) f t h p)))
        [false _] (set out "Problems"))
      (ev/sleep (if (= out "Problems") 1 900)))))
      (ev/sleep (if (= out "Problems") 1 900))
      (buffer/clear b)))
  (shriek/global-cleanup))

M project.janet => project.janet +3 -1
@@ 7,7 7,9 @@
  :url "https://good-place.org/packages/andy.html"
  :dependencies ["spork"
                 "json"
                 "https://github.com/joy-framework/http"
                 {:repo "https://github.com/pepe/jpm"
                  :sha "326762d9af3265203701a1c97afb01689ae71002"}
                 "https://git.sr.ht/~pepe/shriek"
                 "https://git.sr.ht/~pepe/neil"])

(declare-executable :name "andy"