use open meteo api for weather
This commit is contained in:
parent
ae38f7db28
commit
a0f06024ec
1 changed files with 21 additions and 3 deletions
|
@ -37,6 +37,7 @@ check_font() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
temp_unit=celsius
|
||||||
wallpaper_file="${HOME}/wallpaper.jpg"
|
wallpaper_file="${HOME}/wallpaper.jpg"
|
||||||
wallpaper_file2="/etc/lightdm/background.jpg"
|
wallpaper_file2="/etc/lightdm/background.jpg"
|
||||||
archive_folder="${HOME}/earth_pics"
|
archive_folder="${HOME}/earth_pics"
|
||||||
|
@ -49,6 +50,11 @@ font_name=$("${gsettings_cmd}" get org.gnome.desktop.interface font-name | sed "
|
||||||
while [ $# -gt 0 ]
|
while [ $# -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
"--temperature-unit")
|
||||||
|
shift
|
||||||
|
temp_unit="${1}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
"--city")
|
"--city")
|
||||||
shift
|
shift
|
||||||
city="${1}"
|
city="${1}"
|
||||||
|
@ -90,6 +96,15 @@ do
|
||||||
esac
|
esac
|
||||||
done
|
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
|
check_internet || exit 1
|
||||||
|
|
||||||
font_name="$(check_font "${font_name}")"
|
font_name="$(check_font "${font_name}")"
|
||||||
|
@ -179,10 +194,13 @@ fi
|
||||||
if [[ "$o_longitude" == "West" ]]; then
|
if [[ "$o_longitude" == "West" ]]; then
|
||||||
g_longitude="-$g_longitude"
|
g_longitude="-$g_longitude"
|
||||||
fi
|
fi
|
||||||
weather_url="http://api.wunderground.com/api/be78b9c2c0dbd00f/conditions/lang:ES/q/$g_latitude,$g_longitude.xml"
|
weather_url="https://api.wunderground.com/api/be78b9c2c0dbd00f/conditions/lang:ES/q/$g_latitude,$g_longitude.xml"
|
||||||
temperature=$("${curl_cmd}" -s "$weather_url" | egrep -o "<temp_c>-?[0-9]*\.?[0-9]?</temp_c>" | sed "s/<temp_c>//g" - | sed "s|</temp_c>||g" -)
|
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)
|
convert_cmd=$(which convert)
|
||||||
if [ ! -x "${convert_cmd}" ]; then
|
if [ ! -x "${convert_cmd}" ]; then
|
||||||
|
|
Loading…
Reference in a new issue