From 6194f40e0dc656e1e7b5c95a943cae18e6701660 Mon Sep 17 00:00:00 2001 From: Siina Mashek Date: Mon, 25 Apr 2022 04:33:45 +0300 Subject: [PATCH] Moved away from wttr to own API key with openweathermap --- common/weather | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/common/weather b/common/weather index 6680e0c..a0ccbf2 100755 --- a/common/weather +++ b/common/weather @@ -1,6 +1,23 @@ #!/bin/sh +# Requires jq +if ! jq --version &> /dev/null; then + echo "Please install jq" + exit +fi -FORMAT="%C,+%t+(feels+like+%f)" -WEATHER=$(curl -s wttr.in/?format=$FORMAT) +URL="https://api.openweathermap.org/data/2.5/onecall" +LOCATION="Jyväskylä" +LAT_LON="lat=62.23&lon=25.73" +EXCLUDE="exclude=minutely,hourly,daily,alerts" +UNITS="units=metric" +LANG="lang=en" -printf "$WEATHER\n" +# OWM_API_KEY is an environment variable +WHOLE="${URL}?${LAT_LON}&${EXCLUDE}&${WEATHER}&${UNITS}&${LANG}&appid=${OWM_API_KEY}" + +DATA=($(curl -s "${WHOLE}" \ + | jq '.current.temp, .current.feels_like, .current.weather[0].description')) + +DESC="${DATA[@]:2}" + +printf "${LOCATION}: ${DESC:1:-1}, ${DATA[0]}°C (feels like ${DATA[1]}°C)\n"