Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions scripts/weather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fetch_weather_information()
#get weather display
display_weather()
{
fahrenheit=$1
if $fahrenheit; then
display_weather='&u' # for USA system
else
Expand Down Expand Up @@ -66,13 +67,24 @@ forecast_unicode()
fi
}

export -f display_weather
export -f display_location
export -f forecast_unicode
export -f fetch_weather_information

main()
{
# process should be cancelled when session is killed
if timeout 1 bash -c "</dev/tcp/ipinfo.io/443" && timeout 1 bash -c "</dev/tcp/wttr.in/443"; then
echo "$(display_weather)$(display_location)"
if ! weather=$(timeout 3 bash -c "display_weather $fahrenheit"); then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(display_location) is missing here.
Why $fahrenheit only?

echo "Weather Unavailable"
elif ! location=$(timeout 3 bash -c display_location); then
echo "Location Unavailable"
else
echo "${weather}${location}"
fi
else
echo "Weather Unavailable"
echo "Network Error"
fi
}

Expand Down
5 changes: 5 additions & 0 deletions scripts/weather_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fixedlocation=$3
DATAFILE=/tmp/.dracula-tmux-data
LAST_EXEC_FILE="/tmp/.dracula-tmux-weather-last-exec"
RUN_EACH=1200
RETRY_EACH=60
TIME_NOW=$(date +%s)
TIME_LAST=$(cat "${LAST_EXEC_FILE}" 2>/dev/null || echo "0")

Expand All @@ -22,6 +23,10 @@ main()
# Run weather script here
$current_dir/weather.sh $fahrenheit $location "$fixedlocation" > "${DATAFILE}"
echo "${TIME_NOW}" > "${LAST_EXEC_FILE}"
elif grep -q 'Unavailable\|Error' "${DATAFILE}" && [ "$(expr ${TIME_LAST} + ${RETRY_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}"
Expand Down