Keep an eye on current weather conditions on single or multiple locations.

Temperature and cloud coverage information for your preconfigured location.

Posted by Gediminas Siutilas on November 30, 2014

Preface

Current weather information from yahoo.com for your single or multiple locations including temperature and cloud coverage information.

Single location configuration

Script fetches the weather information from yahoo.com based on location id which can be determined at weather location code lookup page by edg3.uk. Default is is Lithuania, Vilnius.

#@@@{Your location ID/CODE}
# Default is VILNIUS, Lithuania
locationID="LHXX0005"
...
run() {
	drawWeatherInfo $locationID VNO
}

Second parameter which is 'VNO' in this example is a label for your location. Label should be applied manually based on your preconfigured location.

.

Multiple location Configuration

Multiple locations can be observed by adding additional request for other locations. Number of locations which can be observed are limited based to space for a weather information on your statusbar.

run() {
	drawWeatherInfo $locationID VNO
	
	drawSeparator
	# - weather information for LA, US
	drawWeatherInfo USCA0638 LA

	drawSeparator	
	# - weather information for Quebec City, Canada
	drawWeatherInfo CAXX0385 QC	
}
* If you downloaded ShellWrangler app this scripts will be packed along with the downloaded application.

Script:

Download
#!/bin/bash

#   ____ __        __ __ _      __                       __         
#  / __// /  ___  / // /| | /| / /____ ___ _ ___  ___ _ / /___  ____
# _\ \ / _ \/ -_)/ // / | |/ |/ // __// _ `// _ \/ _ `// // -_)/ __/
#/___//_//_/\__//_//_/  |__/|__//_/   \_,_//_//_/\_, //_/ \__//_/   
#                                               /___/               
#   ___                     _    ___             _ _ _   _             
#  / __|  _ _ _ _ _ ___ _ _| |_ / __|___ _ _  __| (_) |_(_)___ _ _  ___
# | (_| || | '_| '_/ -_) ' \  _| (__/ _ \ ' \/ _` | |  _| / _ \ ' \(_-<
#  \___\_,_|_| |_| \___|_||_\__|\___\___/_||_\__,_|_|\__|_\___/_||_/__/                                                                      
#
# Script author: gadominas@gmail.com
#   
#   Simple current weather conditions including temperature in Celsius and cloud coverage
# based on your location ID.
#
# You can modify this script in order to concatenate multiple locations.
#
# Point your current location based on https://www.edg3.uk/snippets/weather-location-codes/
#
# Example weather codes for Lithuania
# LHXX0001, Alytus
# LHXX0002, Kaunas 
# LHXX0003, Lentvaris
# LHXX0004, Nemencine
# LHXX0005, Vilnius
# LHXX0006, Palanga
# LHXX0007, Panevezys
# LHXX0008, Klaipeda
# LHXX0009, Siauliai
#
#$$${ Weather conditions in indicator for your location/s. Sky coverage & temperature indicators. }

## Find your location ID from https://www.edg3.uk/snippets/weather-location-codes/
## and configure "locationID" variable to show your weather conditions

#@@@{Your location ID/CODE}
# Default is VILNIUS, Lithuania
locationID="LHXX0005"

function empty {
    local var="$1"
    
    if test -z "$var"
    then
        [[ $( echo "1" ) ]]
        return

    # Return true if var is zero (0 as an integer or "0" as a string)
    elif [ "$var" == 0 2> /dev/null ]
    then
        [[ $( echo "1" ) ]]
        return

    # Return true if var is 0.0 (0 as a float)
    elif [ "$var" == 0.0 2> /dev/null ]
    then
        [[ $( echo "1" ) ]]
        return
    fi

    [[ $( echo "" ) ]]
}

isNotEmpty() {
	if [ -z "$1" -a "$1"!=" " ];
		then
			return 1
	  	else
			return 0
	fi
}

drawWeatherInfo() {
	weather=$(/usr/bin/curl --silent "http://weather.yahooapis.com/forecastrss?p="$1"&u=c" |  \
	 /usr/bin/grep -E '(Current Conditions:|C//' -e 's///' \
	 			  -e 's/<\/b>//' -e 's/
//' \ -e 's///' \ -e 's/<\/description>//') printf "⛅"$2"|" if empty "$weather" then ## in case of empty weather output (connection timeout) printf "?!" else printf "%s " $weather fi } drawSeparator() { printf "%s" "🔸" } run() { drawWeatherInfo $locationID VNO # uncomment in case you need multiple locations #drawSeparator # - weather information for LA, US #drawWeatherInfo USCA0638 LA #drawSeparator # - weather information for Quebec City, Canada #drawWeatherInfo CAXX0385 QC } run