diff --git a/earth_wallpaper.sh b/earth_wallpaper.sh index 17304e2..7aacfd7 100755 --- a/earth_wallpaper.sh +++ b/earth_wallpaper.sh @@ -37,6 +37,7 @@ check_font() { fi } +temp_unit=celsius wallpaper_file="${HOME}/wallpaper.jpg" wallpaper_file2="/etc/lightdm/background.jpg" archive_folder="${HOME}/earth_pics" @@ -49,6 +50,11 @@ font_name=$("${gsettings_cmd}" get org.gnome.desktop.interface font-name | sed " while [ $# -gt 0 ] do case "$1" in + "--temperature-unit") + shift + temp_unit="${1}" + shift + ;; "--city") shift city="${1}" @@ -90,6 +96,15 @@ do esac done +if [ "${temp_unit}" == "celsius" ]; then + short_temp_unit='C' +elif [ "${temp_unit}" == "fahrenheit" ]; then + short_temp_unit='F' +else + message "Temperature unit '${temp_unit}' is not one of 'celsius' or 'fahrenheit'" p + exit 2 +fi + check_internet || exit 1 font_name="$(check_font "${font_name}")" @@ -179,10 +194,13 @@ fi if [[ "$o_longitude" == "West" ]]; then g_longitude="-$g_longitude" fi -weather_url="http://api.wunderground.com/api/be78b9c2c0dbd00f/conditions/lang:ES/q/$g_latitude,$g_longitude.xml" -temperature=$("${curl_cmd}" -s "$weather_url" | egrep -o "-?[0-9]*\.?[0-9]?" | sed "s///g" - | sed "s|||g" -) +weather_url="https://api.wunderground.com/api/be78b9c2c0dbd00f/conditions/lang:ES/q/$g_latitude,$g_longitude.xml" +weather_url="https://api.open-meteo.com/v1/forecast?latitude=${g_latitude}&longitude=${g_longitude}¤t_weather=true&temperature_unit=${temp_unit}" +message "Weather URL: ${weather_url}" +current_weather="$("${curl_cmd}" -s "$weather_url")" +temperature=$(echo "${current_weather}" | jq '.current_weather.temperature') -text="Host: ${hostname}\n${cur_date} at ${time}\n${city} ${temperature}º C" +text="Host: ${HOSTNAME}\n${cur_date} ${time}\n${city} ${temperature}º ${short_temp_unit}" convert_cmd=$(which convert) if [ ! -x "${convert_cmd}" ]; then