From 1934a40ae6e22586afd4c00c8ea630ba8c4ff8b9 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 16 Aug 2026 23:44:30 +0200 Subject: [PATCH] added script for www.weatherapi.com works great so far. You will need an API key for this. --- scripts/getweather-weatherapi.sh | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 scripts/getweather-weatherapi.sh diff --git a/scripts/getweather-weatherapi.sh b/scripts/getweather-weatherapi.sh new file mode 100755 index 0000000..f1ba4e8 --- /dev/null +++ b/scripts/getweather-weatherapi.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# see https://www.weatherapi.com + +JSONFILE="/tmp/weather1.json" +#AQHOME_TOOL="./aqhome-tool.sh" +AQHOME_TOOL="/usr/local/bin/aqhome-tool" + +POS_CITY="$1" +POS_LAT="$2" +POS_LONG="$3" +API_KEY="$4" + +if test -z "$POS_CITY"; then + echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY" + exit 1; +fi + +if test -z "$POS_LAT"; then + echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY" + exit 1; +fi + +if test -z "$POS_LONG"; then + echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY" + exit 1; +fi + + +if test -z "$API_KEY"; then + echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY" + exit 1; +fi + + + +# +# get current weather +# +if ( curl -s -S "https://api.weatherapi.com/v1/current.json?key=$API_KEY&q=$POS_LAT,$POS_LONG&aqi=yes" -o $JSONFILE ); then + $AQHOME_TOOL adddata -J $JSONFILE -c weather -d "$POS_CITY" -N "Temperature" -v "@current/temp_c" -U "C" + $AQHOME_TOOL adddata -J $JSONFILE -c weather -d "$POS_CITY" -N "Humidity" -v "@current/humidity" -U "%" + $AQHOME_TOOL adddata -J $JSONFILE -c weather -d "$POS_CITY" -N "Wetbulb" -v "@current/wetbulb_c" -U "C" + $AQHOME_TOOL adddata -J $JSONFILE -c weather -d "$POS_CITY" -N "pm2_5" -v "@current/air_quality/pm2_5" -U "ug/m3" + $AQHOME_TOOL adddata -J $JSONFILE -c weather -d "$POS_CITY" -N "pm10" -v "@current/air_quality/pm10" -U "ug/m3" +fi +