Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weather.sh: Introduce fallback when wttr.in reaches call limit #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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