aboutsummaryrefslogtreecommitdiff
path: root/cmd/weather
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-05-21 18:56:19 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-05-21 18:56:19 +0200
commit688779fbc61d48046199d1f45549720e289ce417 (patch)
tree4ea8c13d96428176f97c0c27f665391c09a93098 /cmd/weather
parentfb0fd67d6e7e55548c7a0a1ec67f608efffe3a94 (diff)
downloadxmppcb-688779fbc61d48046199d1f45549720e289ce417.tar.gz
xmppcb-688779fbc61d48046199d1f45549720e289ce417.zip
Added support for user generated shell scripts:
- create a director with shell scripts - call them within the chat with @<script-name> - four sample scripts
Diffstat (limited to 'cmd/weather')
-rwxr-xr-xcmd/weather38
1 files changed, 38 insertions, 0 deletions
diff --git a/cmd/weather b/cmd/weather
new file mode 100755
index 0000000..ee21233
--- /dev/null
+++ b/cmd/weather
@@ -0,0 +1,38 @@
+#!/bin/sh
+# @weather [location] - condition, temperature and local time
+#
+# In chat: @weather -> default: Bangkok and Warsaw
+# @weather Wroclaw -> just that location
+# @weather New York -> the whole argument arrives as "$1"
+#
+# Weather comes from wttr.in. Its %T (time) field is served from a cache
+# and goes stale, so we take only the timezone name (%Z, which is
+# static) from wttr.in and compute the current local time with date.
+
+fmt='%l:+%c+%t+%Z'
+
+one() {
+ loc=$(printf '%s' "$1" | tr ' ' '+')
+ out=$(curl -fsS --max-time 8 "https://wttr.in/${loc}?format=${fmt}") || {
+ printf 'weather: lookup failed for %s\n' "$1"
+ return
+ }
+ tz=${out##* } # last token: timezone name, e.g. Asia/Bangkok
+ wx=${out% *} # the rest: location, condition, temperature
+ case "$tz" in
+ */*)
+ now=$(TZ="$tz" date '+%H:%M')
+ printf '%s, %s\n' "$wx" "$now"
+ ;;
+ *)
+ printf '%s\n' "$out" # no usable timezone: show as-is
+ ;;
+ esac
+}
+
+if [ -n "$1" ]; then
+ one "$1"
+else
+ one Bangkok
+ one Warsaw
+fi