tmux-kanagawa/scripts/weather_wrapper.sh
David Dunham 504098ed74 Fix multi word fixed location
If you set the @dracula-fixed-location to "San Diego, California" it
ends up looking at "San" which is somewhere in South Korea. This occurs
for any fixed-location that has a space. Something like
"Portland, Oregon" can be modified to "Portland,Oregon" and still work
but we can't remove the space from "San Diego". The reason that spaces
in the fixed location break the backend request is that dracula.sh loses
everything after the space.

Q: Why does the fixed-location end up as "San"?
A: In dracula.sh the fixed-location is not wrapped in quotes when
embedded in the status-right string.

A: In weather_wrapper.sh the call to weather.sh does not wrap the
fixed-location argument with quotes.

Q: When these are fixed why do we get a broken link?
A: Since we are calling a web service using a url, we need to escape
the spaces by changing them to %20
2024-01-03 17:59:07 -08:00

31 lines
785 B
Bash
Executable file

#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
#wrapper script for running weather on interval
fahrenheit=$1
location=$2
fixedlocation=$3
DATAFILE=/tmp/.dracula-tmux-data
LAST_EXEC_FILE="/tmp/.dracula-tmux-weather-last-exec"
RUN_EACH=1200
TIME_NOW=$(date +%s)
TIME_LAST=$(cat "${LAST_EXEC_FILE}" 2>/dev/null || echo "0")
main()
{
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$(expr ${TIME_LAST} + ${RUN_EACH})" -lt "${TIME_NOW}" ]; then
# Run weather script here
$current_dir/weather.sh $fahrenheit $location "$fixedlocation" > "${DATAFILE}"
echo "${TIME_NOW}" > "${LAST_EXEC_FILE}"
fi
cat "${DATAFILE}"
}
#run main driver function
main