From 107d7ab44058e3ecfcb7eea1fdc0f764682b5682 Mon Sep 17 00:00:00 2001 From: Hugo Licon Date: Sun, 5 Jul 2020 18:22:47 -0600 Subject: [PATCH] add international support for weather module It uses [wttr.in](https://github.com/chubin/wttr.in) to get the weather information and the current city based on the IP address --- scripts/weather.sh | 68 ++++++---------------------------------------- 1 file changed, 9 insertions(+), 59 deletions(-) diff --git a/scripts/weather.sh b/scripts/weather.sh index 985af91..58b03e2 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -3,79 +3,29 @@ fahrenheit=$1 -load_request_params() -{ - - city=$(curl -s https://ipinfo.io/city 2> /dev/null) - region=$(curl -s https://ipinfo.io/region 2> /dev/null) - zip=$(curl -s https://ipinfo.io/postal 2> /dev/null | tail -1) - country_w_code=$(curl -w "\n%{http_code}\n" -s https://ipinfo.io/country 2> /dev/null) - country=`grep -Eo [a-zA-Z]+ <<< "$country_w_code"` - exit_code=`grep -Eo [0-9]{3} <<< "$country_w_code"` - - region_code_url=http://www.ip2country.net/ip2country/region_code.html - weather_url=https://forecast.weather.gov/zipcity.php -} - -#substitute region code for regions in north america -get_region_code() -{ - curl -s $region_code_url | grep $region &> /dev/null && region=$(curl -s $region_code_url | grep $region | cut -d ',' -f 2) - echo $region -} - weather_information() { - curl -sL $weather_url?inputstring=$zip | grep myforecast-current | grep -Eo '>.*<' | sed -E 's/>(.*)/dev/null; then - echo "$(display_weather)$city, $(get_region_code)" + echo "$(display_weather)" else echo "Location Unavailable" fi