summaryrefslogtreecommitdiff
path: root/lib/silmataivas/ntfy_notifier.ex
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-03-23 17:11:39 +0100
committerDawid Rycerz <dawid@rycerz.xyz>2025-04-05 21:16:51 +0200
commit0ab2e5ba2b0631b28b5b1405559237b3913c878f (patch)
tree791cea788b0a62bc483d0041fbd0c655d2ad49e8 /lib/silmataivas/ntfy_notifier.ex
feat: initialize Phoenix application for weather alerts
This commit sets up the initial Silmataivas project structure, including: Phoenix web framework configuration, database models for users and locations, weather polling service, notification system, Docker and deployment configurations, CI/CD pipeline setup
Diffstat (limited to 'lib/silmataivas/ntfy_notifier.ex')
-rw-r--r--lib/silmataivas/ntfy_notifier.ex35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/silmataivas/ntfy_notifier.ex b/lib/silmataivas/ntfy_notifier.ex
new file mode 100644
index 0000000..26815db
--- /dev/null
+++ b/lib/silmataivas/ntfy_notifier.ex
@@ -0,0 +1,35 @@
+defmodule Silmataivas.Notifications.NtfyNotifier do
+ @moduledoc """
+ Sends push notifications using ntfy.sh.
+ """
+
+ @ntfy_url System.get_env("NTFY_URL") || "https://ntfy.sh"
+
+ def send_alert(
+ topic,
+ %{
+ "main" => %{"temp" => temp},
+ "wind" => %{"speed" => speed},
+ "dt_txt" => time_str
+ } = entry
+ ) do
+ rain_mm = get_in(entry, ["rain", "3h"]) || 0.0
+ wind_kmh = speed * 3.6
+
+ message = """
+ 🚨 Weather alert for your location (#{time_str}):
+
+ 🌬️ Wind: #{Float.round(wind_kmh, 1)} km/h
+ 🌧️ Rain: #{rain_mm} mm
+ 🌡️ Temperature: #{temp} °C
+
+ Stay safe,
+ — Silmätaivas
+ """
+
+ Req.post("#{@ntfy_url}/#{topic}",
+ headers: [{"Priority", "5"}],
+ body: message
+ )
+ end
+end