29 lines
680 B
Bash
Executable File
29 lines
680 B
Bash
Executable File
#!/bin/sh
|
|
# Requires jq
|
|
if ! jq --version &> /dev/null; then
|
|
echo "Please install jq"
|
|
exit
|
|
fi
|
|
|
|
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"
|
|
|
|
# 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}"
|
|
|
|
# If no data, exit
|
|
if [[ $DATA == *"null"* ]]; then
|
|
exit
|
|
fi
|
|
|
|
printf "${LOCATION}: ${DESC:1:-1}, ${DATA[0]}°C (fl ${DATA[1]}°C)\n"
|