I3blocks weather script

22:24:00 0 Comments


The script works smooth with i3blocks. It's a fork written by me, you have to install curls in order to make it work.
Script:

#!/bin/bash
# Based on http://openweathermap.org/current

API_KEY="PutYourPersonalKeyHere"

# Check on http://openweathermap.org/find
CITY_ID="3105971"

ICON_SUNNY=""
ICON_CLOUDY=""
ICON_RAINY=""
ICON_STORM=""
ICON_SNOW=""
ICON_FOG=""

SYMBOL_CELSIUS="℃"

WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&appid=${API_KEY}&units=metric"
WEATHER_INFO=$(curl --silent ${WEATHER_URL})
WEATHER_MAIN=$(echo ${WEATHER_INFO}|grep -o -e '\"main\":\"[a-Z]*\"'| awk -F ':' '{print $2}' | tr -d '"')
WEATHER_TEMP=$(echo ${WEATHER_INFO}|grep -o -e '\"temp\":\-\?[0-9]*' | awk -F ':' '{print $2}' | tr -d '"')
WEATHER_CITY=$(echo ${WEATHER_INFO}|grep -o -e '\"name\":\"[a-Z]*\"'| awk -F ':' '{print $2}' | tr -d '"')

if [[ "${WEATHER_MAIN}" = *Snow* ]]; then
  echo "${WEATHER_CITY} ${ICON_SNOW} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
  elif [[ "${WEATHER_MAIN}" = *Rain* ]] || [[ "${WEATHER_MAIN}" = *Drizzle* ]]; then
  echo "${WEATHER_CITY} ${ICON_RAINY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
  elif [[ "${WEATHER_MAIN}" = *Cloud* ]]; then
  echo -e  "${WEATHER_CITY} ${ICON_CLOUDY} ${COLOR}${WEATHER_TEMP}${SYMBOL_CELSIUS}"
 elif [[ "${WEATHER_MAIN}" = *Clear* ]]; then
  echo "${WEATHER_CITY} ${ICON_SUNNY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
  elif [[ "${WEATHER_MAIN}" = *Fog* ]] || [[ "${WEATHER_MAIN}" = *Mist* ]]; then
  echo "${WEATHER_CITY} ${ICON_FOG} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
  echo "${WEATHER_CITY} ${WEATHER_MAIN} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
  fi

An API_KEY is needed, you can get one on openweathermap, it's free. Then edit api_key field with your custom key.

Add this couple of lines in i3blocks file:



#Weather

[weather]

interval=120

command=~/path_to_script
fi

Enjoy !!!

0 comentarios: