Created
          July 1, 2024 13:19 
        
      - 
      
- 
        Save MaverickEsq/d2fce7f31650a815075c6eb991c51045 to your computer and use it in GitHub Desktop. 
    A snippet to display wttr.in weather and refresh it every interval
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # Uses wttr.in to display weather in terminal | |
| # Low values of `r` are rude. Don't overload wttr.in | |
| # -l is location as postcode, airport code, or location name. IE ADL, Port Adelaide, 5014+SA | |
| # -r is refresh rate in minutes. You do not need minute by minute updates. | |
| # -b is blanking. Will blank out the terminal at the begining of each update if set. | |
| usage() { echo "Usage: $0 [-l <location>] [-r <refresh rate>] [-b]" 1>&2; exit 1; } | |
| LINES=$(tput lines) | |
| while getopts "bl:r:" o; do | |
| case "${o}" in | |
| l) l=${OPTARG} ;; | |
| r) r=$((OPTARG * 60)) ;; | |
| b) b=1 ;; | |
| *) usage ;; | |
| esac | |
| done | |
| if [[ -z $r || -z $l ]]; then | |
| usage | |
| fi | |
| while true | |
| do | |
| if [[ -n $b ]]; then | |
| printf '%0.s\n' {1..$(seq $LINES)} | |
| fi | |
| n=`date --date=+"+$r seconds"` | |
| curl -s 'wttr.in/'${l}'?1&n&F&Q' | sed '1 s/^/\n\n/' | sed 's/^/ /' && echo -e "\n Last updated: `date`\n Next update: $n\n" | |
| sleep ${r} | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment