From 827e804567b78eb7f8e2bdcfc1a9b77146992292 Mon Sep 17 00:00:00 2001
From: Silvio Rhatto <rhatto@riseup.net>
Date: Tue, 20 Aug 2024 21:01:26 -0300
Subject: Initial import

---
 weather-forecast | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100755 weather-forecast

(limited to 'weather-forecast')

diff --git a/weather-forecast b/weather-forecast
new file mode 100755
index 0000000..269f740
--- /dev/null
+++ b/weather-forecast
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Simple wrapper around wttr.in
+#
+
+# Parameters
+BASENAME="`basename $0`"
+PROGRAM="$1"
+CACHE="$HOME/.local/share/weather"
+
+# Load config
+source $HOME/.custom/wttr.in.conf || exit 1
+
+# weather-forecast service query
+function weather_forecast_query {
+  # Make sure everything we need exists
+  mkdir -p $CACHE
+  touch $CACHE/weather-forecast.cur $CACHE/weather-forecast.prev
+
+  # Save the previous forecast
+  cp $CACHE/weather-forecast.cur $CACHE/weather-forecast.prev
+  curl wttr.in/$LOCATION > $CACHE/weather-forecast.cur 2> /dev/null
+
+  # Test if current forecast is empty, meaning
+  # that we're probably ofline. In that case
+  # we provide the previous output.
+  if [ ! -s "$CACHE/weather-forecast.cur" ]; then
+    cp $CACHE/weather-forecast.prev $CACHE/weather-forecast.cur
+  fi
+
+  # Display output
+  cat $CACHE/weather-forecast.cur
+}
+
+# Main
+weather_forecast_query
-- 
cgit v1.2.3