From 81f8bc60535659354707161cac0e92eca1af183c Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sat, 19 Jun 2021 13:38:15 -0500 Subject: [PATCH] Add location tracking --- happybot/weather.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/happybot/weather.sh b/happybot/weather.sh index 7fc40f5..819a5fd 100644 --- a/happybot/weather.sh +++ b/happybot/weather.sh @@ -9,9 +9,20 @@ irc | while read -r n m; do place="$(m 1)" elif hreg '^#(?:temp|temperature|weather) (.*)$' "$m"; then place="$(m 1)" + elif hreg '^#at (.*)$' "$m" + place="$(m 1)" + if grep -q "^$n," places.csv; then + sed 's|^'"$n"',.*|'"$n,$place"'|' > places-new.csv + mv -f places-new.csv places.csv + else + printf '%s,%s' "$n" "$place" >> places.csv + fi else continue; fi + if [ -z "$1" ]; then + place=$(awk -F, -v "n=$n" '$1==n{print $2}' places.csv) + fi plason="$(curl -s -g -G --data-urlencode "q=$place" --data-urlencode 'format=json' 'https://nominatim.openstreetmap.org/search')" if [ "x$plason" == "x[]" ]; then answer="Could not find location: $place"