v.0.3 - forecast and a bit of CLI overhaul
This commit is contained in:
parent
eca9e097f5
commit
d3b4f6d738
2 changed files with 49 additions and 27 deletions
|
|
@ -13,5 +13,9 @@ v.0.2\
|
||||||
#uwufy everything --- DONE(though it's a constant process)\
|
#uwufy everything --- DONE(though it's a constant process)\
|
||||||
|
|
||||||
v.0.3\
|
v.0.3\
|
||||||
#add 24-hour forecast as an option\
|
#add 24-hour forecast as an option --- DONE\
|
||||||
#add ANSI/ASCII art as icons for weather descriptions(not sure yet)
|
#add ANSI/ASCII art as icons for weather descriptions(not sure yet) --- DISCARDED\
|
||||||
|
#CLI overhaul for new features --- DONE\
|
||||||
|
|
||||||
|
v.1.0(initial release)\
|
||||||
|
#TBA
|
||||||
66
weather.sh
Normal file → Executable file
66
weather.sh
Normal file → Executable file
|
|
@ -4,6 +4,8 @@
|
||||||
#colorcode the output --- DONE
|
#colorcode the output --- DONE
|
||||||
#automatic detection of package manager to install jq(at least apt/pacman/xbps/etc..) --- DONE(semi-auto preferred)
|
#automatic detection of package manager to install jq(at least apt/pacman/xbps/etc..) --- DONE(semi-auto preferred)
|
||||||
#uwufy everything --- DONE uwu~
|
#uwufy everything --- DONE uwu~
|
||||||
|
#add 24-hour forecast as an option --- DONE
|
||||||
|
#add ANSI/ASCII art as icons for weather descriptions(not sure yet) --- DISCARDED
|
||||||
|
|
||||||
#verify if user has jq installed
|
#verify if user has jq installed
|
||||||
if ! command -v jq &> /dev/null; then
|
if ! command -v jq &> /dev/null; then
|
||||||
|
|
@ -29,50 +31,66 @@ case $choice in
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
strip_ansi_escape_codes() {
|
||||||
|
echo -ne "$1" | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"
|
||||||
|
}
|
||||||
|
pad_string() {
|
||||||
|
local string="$1"
|
||||||
|
local length="$2"
|
||||||
|
local stripped=""
|
||||||
|
stripped=$(strip_ansi_escape_codes "$string")
|
||||||
|
local spaces=$((length - ${#stripped}))
|
||||||
|
printf "%s%*s" "$string" "$spaces" ""
|
||||||
|
}
|
||||||
|
|
||||||
api_key="a6c3cfde026d31b995612c6f169203a7"
|
api_key="a6c3cfde026d31b995612c6f169203a7"
|
||||||
ipinfo_key="bd1acc5f04e870"
|
ipinfo_key="bd1acc5f04e870"
|
||||||
user_ip=$(curl -s https://ifconfig.me/ip)
|
user_ip=$(curl -s https://ifconfig.me/ip)
|
||||||
#echo $user_ip
|
|
||||||
|
|
||||||
location_info=$(curl -s https://ipinfo.io/$user_ip?token=$ipinfo_key)
|
location_info=$(curl -s https://ipinfo.io/$user_ip?token=$ipinfo_key)
|
||||||
#echo $location_info
|
|
||||||
lat=$(echo "$location_info" | jq -r '.loc' | cut -d ',' -f 1)
|
lat=$(echo "$location_info" | jq -r '.loc' | cut -d ',' -f 1)
|
||||||
lon=$(echo "$location_info" | jq -r '.loc' | cut -d ',' -f 2)
|
lon=$(echo "$location_info" | jq -r '.loc' | cut -d ',' -f 2)
|
||||||
|
|
||||||
#echo $lat $lon
|
|
||||||
|
|
||||||
|
|
||||||
api_url="https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&units=metric&appid=$api_key"
|
api_url="https://api.openweathermap.org/data/2.5/weather?lat=$lat&lon=$lon&units=metric&appid=$api_key"
|
||||||
#echo $api_url
|
forecast_url="https://api.openweathermap.org/data/2.5/forecast?lat=$lat&lon=$lon&units=metric&appid=$api_key"
|
||||||
|
|
||||||
weather_data=$(curl -s "$api_url")
|
weather_data=$(curl -s "$api_url")
|
||||||
#echo $weather_data
|
forecast_data=$(curl -s "$forecast_url")
|
||||||
|
|
||||||
weather_desc=$(echo "$weather_data" | jq -r '.weather[].description')
|
weather_desc=$(echo "$weather_data" | jq -r '.weather[].description')
|
||||||
|
|
||||||
city=$(echo "$weather_data" | jq -r '.name')
|
city=$(echo "$weather_data" | jq -r '.name')
|
||||||
if [[ "$city" == "Nur-Sultan" ]] ; then
|
if [[ "$city" == "Nur-Sultan" ]] ; then
|
||||||
city='Astana';
|
city='Astana';
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "\e[37mhewwo \e[35m$USER!\e[37m i hope u awe doing gweat today!\e[0m"
|
echo -e "\t\e[37mhewwo \e[35m$USER!\e[37m i hope u awe doing gweat today!\e[0m"
|
||||||
echo -e "\e[37mhewe is the cuwwent weathew wepowt fow \e[32m$city\e[37m uwu~\e[0m"
|
echo -e "\t\e[37mhewe is the cuwwent weathew wepowt fow \e[32m$city\e[37m uwu~\e[0m"
|
||||||
echo -e "\e[32m--------------------------------------------\e[0m"
|
echo
|
||||||
echo -e "\e[37mtime: $(date +"%H:%M")\e[37m"
|
echo -e "\e[32m$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =)\e[0m"
|
||||||
echo -e "date: $(date +"%d/%m/%Y")"
|
echo -e "\e[32m\t$(pad_string "cuwwent" 40) fowecast"
|
||||||
echo -e "weathew: \e[33m\e[5m$(echo "$weather_data" | jq -r '.weather[].description')\e[0m"
|
echo -e "\e[32m$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -)\e[0m"
|
||||||
echo -e "\e[37mtempewature: \e[37m\e[35m$(echo "$weather_data" | jq -r '.main.temp')°C\e[0m"
|
echo
|
||||||
echo -e "\e[37mwind: \e[37m\e[36m$(echo "$weather_data" | jq -r '.wind.speed')m/s, azimuth: $(echo "$weather_data" | jq -r '.wind.deg')\e[0m"
|
echo -e "\t$(pad_string "\e[37mtime: $(date +"%H:%M")" 40)\e[0m $(echo "$forecast_data" | jq -r '.list[0].dt_txt' | sed 's#-#/#g;s#...$##;') ----- \e[33m$(echo "$forecast_data" | jq -r '[.list[0].weather[].description, .list[0].main.temp] | join(", ")')°C\e[0m"
|
||||||
echo -e "\e[37mcwouds: \e[37m\e[34m$(echo "$weather_data" | jq -r '.clouds.all')%\e[0m"
|
echo -e "\t$(pad_string "\e[37mdate: $(date +"%d/%m/%Y")" 40)\e[0m $(echo "$forecast_data" | jq -r '.list[1].dt_txt' | sed 's#-#/#g;s#...$##') ----- \e[33m$(echo "$forecast_data" | jq -r '[.list[1].weather[].description, .list[1].main.temp] | join(", ")')°C\e[0m"
|
||||||
echo -e "\e[32m--------------------------------------------\e[0m"
|
echo -e "\t$(pad_string "weathew: \e[33m\e[5m$(echo "$weather_data" | jq -r '.weather[].description')\e[0m" 40) $(echo "$forecast_data" | jq -r '.list[2].dt_txt' | sed 's#-#/#g;s#...$##') ----- \e[33m$(echo "$forecast_data" | jq -r '[.list[2].weather[].description, .list[2].main.temp] | join(", ")')°C\e[0m"
|
||||||
|
echo -e "\t$(pad_string "\e[37mtempewature: \e[35m$(echo "$weather_data" | jq -r '.main.temp')°C\e[0m" 40) $(echo "$forecast_data" | jq -r '.list[3].dt_txt' | sed 's#-#/#g;s#...$##') ----- \e[33m$(echo "$forecast_data" | jq -r '[.list[3].weather[].description, .list[3].main.temp] | join(", ")')°C\e[0m"
|
||||||
|
echo -e "\t$(pad_string "\e[37mwind: \e[37m\e[36m$(echo "$weather_data" | jq -r '.wind.speed')m/s, azimuth: $(echo "$weather_data" | jq -r '.wind.deg')\e[0m" 40) $(echo "$forecast_data" | jq -r '.list[4].dt_txt' | sed 's#-#/#g;s#...$##') ----- \e[33m$(echo "$forecast_data" | jq -r '[.list[4].weather[].description, .list[4].main.temp] | join(", ")')°C\e[0m"
|
||||||
|
echo -e "\t$(pad_string "\e[37mcwouds: \e[37m\e[34m$(echo "$weather_data" | jq -r '.clouds.all')%\e[0m" 40) $(echo "$forecast_data" | jq -r '.list[5].dt_txt' | sed 's#-#/#g;s#...$##') ----- \e[33m$(echo "$forecast_data" | jq -r '[.list[5].weather[].description, .list[5].main.temp] | join(", ")')°C\e[0m"
|
||||||
|
echo
|
||||||
|
echo -e "\e[32m$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -)\e[0m"
|
||||||
if [[ "$weather_desc" == "clear sky" ]]; then
|
if [[ "$weather_desc" == "clear sky" ]]; then
|
||||||
echo -e "\e[33mseems to be a pwetty cleaw sky today!\e[0m"
|
echo -e "\t\e[33mseems to be a pwetty cleaw sky today!\e[0m"
|
||||||
elif [[ "$weather_desc" == *"clouds"* ]]; then
|
elif [[ "$weather_desc" == *"clouds"* ]]; then
|
||||||
echo -e "\e[34msome cwouds awe pwesent but it's ok :3 i like cwouds!!!!\e[0m"
|
echo -e "\t\e[34msome cwouds awe pwesent but it's ok :3 i like cwouds!!!!\e[0m"
|
||||||
elif [[ "$weather_desc" == *"rain"* ]]; then
|
elif [[ "$weather_desc" == *"rain"* || "$weather_desc" == *"drizzle"* ]]; then
|
||||||
echo -e "\e[36mlooks like it's wainin today, make suwe u bwing an umbwella with u :3\\e[0m"
|
echo -e "\t\e[36mlooks like it's wainin today, make suwe u bwing an umbwella with u :3\\e[0m"
|
||||||
elif [[ "$weather_desc" == *"thunderstorm"* ]]; then
|
elif [[ "$weather_desc" == *"thunderstorm"* ]]; then
|
||||||
echo -e "\e[31ma thundewsowm is coming! pwepawe youwself!\e[0m"
|
echo -e "\t\e[31ma thundewsowm is coming! pwepawe youwself!\e[0m"
|
||||||
elif [[ "$weather_desc" == *"snow"* ]]; then
|
elif [[ "$weather_desc" == *"snow"* ]]; then
|
||||||
echo -e "\e[37mthewe is going to be snow today! be caweful outside~\e[0m"
|
echo -e "\t\e[37mthewe is going to be snow today! be caweful outside~\e[0m"
|
||||||
elif [[ "$weather_desc" == "fog" || "$weather_desc" == "mist" ]]; then
|
elif [[ "$weather_desc" == "fog" || "$weather_desc" == "mist" ]]; then
|
||||||
echo -e "\e[31mthe fog is coming uwu~\e[0m"
|
echo -e "\t\e[31mthe fog is coming uwu~\e[0m"
|
||||||
fi
|
fi
|
||||||
|
echo -e "\e[32m$(printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =)\e[0m"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue