change weather api

This commit is contained in:
c0dev0id 2023-12-24 11:11:13 +01:00
parent 6a0ee2ac53
commit b5cc10a0cc

View File

@ -162,10 +162,34 @@ usage() {
# $1 loc
weather() {
l=$1
[ -z "$l" ] \
&& l=heidelberg
say "$(curl -s "https://wttr.in/$l?lang=de&format=%l:+%t+%C+%w+%h+Regen")"
param=$1
[ -z $param ] \
&& param=Heidelberg,DE
echo "$param" | fgrep -q "," \
|| param="$param,DE"
DATA=$(curl -s "https://api.openweathermap.org/data/2.5/weather?q=$param&lang=de&units=metric&appid=a4c6e6d6beba2ff733ed81b7e2cac530")
#DATA=$(cat test.json)
RESPONSE=$(echo "$DATA" \
| jq -rc '.name,[.main.temp, .weather[].description][], .main.humidity, .wind.speed' 2> /dev/null \
| awk ' \
NR == 1 { printf("Wetter in %s: ", $0) } \
NR == 2 { printf("%.0d°C, ", $0) } \
NR == 3 { printf("%s", $0) } \
NR == 4 { printf(" (%d%%), ", $0) } \
NR == 5 { printf("Wind: %.0dkm/h", $0) } \
')
case "$RESPONSE" in
*null:*) RESPONSE="$param konnte nicht gefunden werden. Usage: !wetter <stadt>[,<länderkürzel>]"
esac
say "$RESPONSE"
}
@ -225,7 +249,7 @@ do
# character set for safety reasons.
ARG=$(echo "$line" \
| tr '[:upper:]' '[:lower:]' \
| sed -n 's|.*![a-z]* \([a-zA-Z0-9\-_+]*\).*|\1|p')
| sed -n 's|.*![a-z]* \([a-zA-Z0-9,\-_+]*\).*|\1|p')
# We call it gummipunkte now.
KARMA=$(echo "$line" \