metalx1000

BASH Current Weather

Jun 25th, 2021 (edited)
2,471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.58 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2021  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. url="http://wttr.in/?format=j1"
  21. json="$(wget -qO- "$url")"
  22.  
  23. #color library
  24. default=`echo -en "\e[39m"`
  25. red=`echo -en "\e[31m"`
  26. orange=`echo -en "\e[33m"`
  27. blue=`echo -en "\e[34m"`
  28.  
  29. bold=`echo -en "\e[1m"`
  30. normal=`echo -en "\e[0m"`
  31.  
  32. temp=$(echo $json|jq -r ."current_condition[0]|(.temp_F)")
  33. humidity=$(echo $json|jq -r ."current_condition[0]|.humidity")
  34. description=$(echo $json|jq -r ."current_condition[0]|(.weatherDesc[0].value)")
  35.  
  36. if [[ ${temp} > 90 ]]
  37. then
  38.   color=${red}
  39. elif [[ ${temp} > 75 ]]
  40. then
  41.   color=${orange}
  42. elif [[ ${temp} < 50 ]]
  43. then
  44.   color=${blue}
  45. else
  46.   color=""
  47. fi
  48.  
  49. echo "It is currently ${bold}${description}${normal}"
  50. echo "${color}Temperature: ${temp}${default}"
  51. echo "Humidity: ${humidity}%"
Add Comment
Please, Sign In to add comment