Skip to content

Commit 4cfaa3d

Browse files
Merge pull request #308 from fvincenzo/master
weather.sh: Introduce fallback when wttr.in reaches call limit
2 parents 68a7ddb + e010441 commit 4cfaa3d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

scripts/weather.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ display_weather()
5353
temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
5454
unicode=$(forecast_unicode $weather_condition)
5555

56-
echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature
56+
# Mac Only variant should be transparent on Linux
57+
if [[ "${temperature/+/}" == *"===="* ]]; then
58+
temperature="error"
59+
fi
60+
61+
if [[ "${temperature/+/}" == "error" ]]; then
62+
# Propagate Error
63+
echo "error"
64+
else
65+
echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature
66+
fi
5767
}
5868

5969
forecast_unicode()
@@ -76,7 +86,7 @@ forecast_unicode()
7686
main()
7787
{
7888
# process should be cancelled when session is killed
79-
if timeout 1 bash -c "</dev/tcp/ipinfo.io/443" && timeout 1 bash -c "</dev/tcp/wttr.in/443"; then
89+
if timeout 1 bash -c "</dev/tcp/ipinfo.io/443" && timeout 1 bash -c "</dev/tcp/wttr.in/443" && [[ "$(display_weather)" != "error" ]]; then
8090
echo "$(display_weather)$(display_location)"
8191
else
8292
echo "Weather Unavailable"

0 commit comments

Comments
 (0)