Skip to content

Commit

Permalink
Merge pull request #308 from fvincenzo/master
Browse files Browse the repository at this point in the history
weather.sh: Introduce fallback when wttr.in reaches call limit
  • Loading branch information
ethancedwards8 authored Jan 1, 2025
2 parents 68a7ddb + e010441 commit 4cfaa3d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/weather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ display_weather()
temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
unicode=$(forecast_unicode $weather_condition)

echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature
# Mac Only variant should be transparent on Linux
if [[ "${temperature/+/}" == *"===="* ]]; then
temperature="error"
fi

if [[ "${temperature/+/}" == "error" ]]; then
# Propagate Error
echo "error"
else
echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature
fi
}

forecast_unicode()
Expand All @@ -76,7 +86,7 @@ forecast_unicode()
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
if timeout 1 bash -c "</dev/tcp/ipinfo.io/443" && timeout 1 bash -c "</dev/tcp/wttr.in/443" && [[ "$(display_weather)" != "error" ]]; then
echo "$(display_weather)$(display_location)"
else
echo "Weather Unavailable"
Expand Down

0 comments on commit 4cfaa3d

Please sign in to comment.