You are not logged in.
I'm using tint2-weather script executor by
addy-dclxv
#!/bin/bash
# I take this script from Anachron's i3blocks
# I only slightly modify this script to add an option to show icon
# I also remove the i3blocks specify script
# To make this works with tint2 executor, polybar custom script, dzen2 feeder, conkybar, lemonbar feeder, dunst notify, etc.
# 'weather -i' = with icon, 'weather' = text only
# Cheers!
# Addy
# Open Weather Map API code, register to http://openweathermap.org to get one ;)
API_KEY="365a6f3a274bba21cabdbee0aa44exxx"
# Check on http://openweathermap.org/find
CITY_ID="1650xxx"
ICON_SUNNY=" Clear"
ICON_CLOUDY=" Cloudy"
ICON_RAINY=" Rainy"
ICON_STORM=" Storm"
ICON_SNOW=" Snow"
ICON_FOG=" Fog"
ICON_MISC=" "
TEXT_SUNNY="Clear"
TEXT_CLOUDY="Cloudy"
TEXT_RAINY="Rainy"
TEXT_STORM="Storm"
TEXT_SNOW="Snow"
TEXT_FOG="Fog"
SYMBOL_CELSIUS="˚C"
WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&appid=${API_KEY}&units=metric"
WEATHER_INFO=$(wget -qO- "${WEATHER_URL}")
WEATHER_MAIN=$(echo "${WEATHER_INFO}" | grep -o -e '\"main\":\"[A-Za-z]*\"' | awk -F ':' '{print $2}' | tr -d '"')
WEATHER_TEMP=$(echo "${WEATHER_INFO}" | grep -o -e '\"temp\":\-\?[0-9]*' | awk -F ':' '{print $2}' | tr -d '"')
if [[ "${WEATHER_MAIN}" = *Snow* ]]; then
if [[ $1 = "-i" ]]; then
echo "${ICON_SNOW} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
echo "${TEXT_SNOW} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
fi
elif [[ "${WEATHER_MAIN}" = *Rain* ]] || [[ "${WEATHER_MAIN}" = *Drizzle* ]]; then
if [[ $1 = "-i" ]]; then
echo "${ICON_RAINY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
echo "${TEXT_RAINY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
fi
elif [[ "${WEATHER_MAIN}" = *Cloud* ]]; then
if [[ $1 = "-i" ]]; then
echo "${ICON_CLOUDY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
echo "${TEXT_CLOUDY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
fi
elif [[ "${WEATHER_MAIN}" = *Clear* ]]; then
if [[ $1 = "-i" ]]; then
echo "${ICON_SUNNY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
echo "${TEXT_SUNNY} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
fi
elif [[ "${WEATHER_MAIN}" = *Fog* ]] || [[ "${WEATHER_MAIN}" = *Mist* ]]; then
if [[ $1 = "-i" ]]; then
echo "${ICON_FOG} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
echo "${TEXT_FOG} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
fi
else
if [[ $1 = "-i" ]]; then
echo "${ICON_MISC} ${WEATHER_MAIN} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
else
echo "${WEATHER_MAIN} ${WEATHER_TEMP}${SYMBOL_CELSIUS}"
fi
fi
So far, it goes smoothly with the exception of if my internet connection goes down. I would like to add a message there is no connection.
Could someone set if eth0 present (weather-url) else if no connection (con-down)
I know how to do on conky, but i'm not that good on bash.
Thanks in advance!
Nili
Last edited by Nili (2020-08-30 19:37:40)
Offline
The bunsenweather script uses a connection test, which you could adapt I guess
connectiontest() {
local -i i attempts=${1-0}
for (( i=0; i < attempts || attempts == 0; i++ )); do
if wget -O - 'http://ftp.debian.org/debian/README' &> /dev/null; then
return 0
fi
if (( i == attempts - 1 )); then # if last attempt
return 1
fi
done
}
A code snippet which might work is
if wget -O - 'http://ftp.debian.org/debian/README' &> /dev/null; then
return 0
else
notify-send "No internet connection"
return 1
fi
You could probably also parse the output from a ping command instead.
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Thank you damo, I have difficult to adapt those two scripts you showed, but the ping output you gave me an idea because i already have a little snippets.
ping -qc1 8.8.8.8 2>&1 | awk -F/ '/^rtt/ { printf "%.2f", $5; ok = 1 } END { if (!ok) print "eth0 FAIL" }'
# Fixed this display link down when there's error from network connection.
if ping -qc1 1.1.1.1 >/dev/null; then
WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&appid=${API_KEY}&units=metric"
else
echo " Link Down"
fi
Thank you!
Last edited by Nili (2020-08-30 20:02:36)
Offline
Building on Addy's tint2 weather script executor - and Nili's ping-check for network connection.
I reworked the script to draw the current icon details from openweathermap server output - which are then set from an icon folder in tint2-executor path.
This way, the correct 'day' or 'night' icon is set in the toolbar widget.
Script allows to call the original openweathermap icons, or the relevant Papirus icons
here is the updated 'weather' script :
#!/bin/bash
#
# ===========================================================
# Based on script from @Anachron's i3blocks, as well as
# @Addy's icon additions and @Nili's network-connection check
# Mod by @ceeslans, to draw icons from tint2 config folder
# ===========================================================
# Open Weather Map API code, register to http://openweathermap.org to get one :
API_KEY="f6853011e20f4063f8808bcc74e25b84"
# Check on http://openweathermap.org/find :
CITY_ID="2747891"
# Select applicable temperature symbol "˚C" or "˚F" :
SYMBOL_CELSIUS="˚C"
# Change "Text" to your preferred language :
TEXT_SNOW="Snow"
TEXT_RAINY="Rainy"
TEXT_DRIZZLE="Drizzle"
TEXT_SHOWERS="Showers"
TEXT_SUNNY="Sunny"
TEXT_CLEAR="Clear"
TEXT_CLOUDY="Cloudy"
TEXT_OVERCAST="Overcast"
TEXT_STORM="Storm"
TEXT_FOG="Fog"
# Show Papirus weather-icons :
ICONPATH="$HOME/.config/tint2/executors/icons/weather/"
# or show original openweathermap weather-icons :
#ICONPATH="$HOME/.config/tint2/executors/icons/weather/openweathermap/"
# Don't change these lines, unless you know what you're doing...
if ping -qc1 1.1.1.1 >/dev/null; then
WEATHER_URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&appid=${API_KEY}&units=metric"
else
echo "${ICONPATH}404.png"
echo "Link Down"
fi
WEATHER_INFO=$(wget -qO- "${WEATHER_URL}")
WEATHER_MAIN=$(echo "${WEATHER_INFO}" | grep -o -e '\"main\":\"[A-Za-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_ICON=$(echo "${WEATHER_INFO}" | grep -o -e '\"icon\":\"[0-9a-z]*\"' | awk -F ':' '{print $2}' | tr -d '"')
# To add short condition description in the toolbar, comment out # ${TEXT-*} :
if [[ "${WEATHER_MAIN}" = *Snow* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_SNOW}"
elif [[ "${WEATHER_MAIN}" = *Rain* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_RAINY}"
elif [[ "${WEATHER_MAIN}" = *Drizzle* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_DRIZZLE}"
elif [[ "${WEATHER_MAIN}" = *Shower* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_SHOWERS}"
elif [[ "${WEATHER_MAIN}" = *Sunny* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_SUNNY}"
elif [[ "${WEATHER_MAIN}" = *Clear* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_CLEAR}"
elif [[ "${WEATHER_MAIN}" = *Cloud* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_CLOUDY}"
elif [[ "${WEATHER_MAIN}" = *Overcast* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_OVERCAST}"
elif [[ "${WEATHER_MAIN}" = *Storm* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_STORM}"
elif [[ "${WEATHER_MAIN}" = *Fog* ]]; then
echo "${ICONPATH}${WEATHER_ICON}"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS}" # "${TEXT_FOG}"
else
echo "${ICONPATH}04.png"
echo "${WEATHER_TEMP}${SYMBOL_CELSIUS} ${WEATHER_MAIN}"
fi
and example executor config for tint2:
# Executor 6 (weather local)
execp = new
execp_command = ~/.config/tint2/executors/weather
execp_interval = 300
execp_has_icon = 1
execp_cache_icon = 1
execp_continuous = 0
execp_markup = 1
execp_tooltip = Current weather --> leftclick for 7days weather forecast
execp_lclick_command = exo-open https://openweathermap.org/city/2747891
execp_rclick_command =
execp_mclick_command =
execp_uwheel_command =
execp_dwheel_command =
execp_font = DejaVu Sans Condensed 9
execp_font_color = #ffffff 100
execp_padding = 6 0
execp_background_id = 0
execp_centered = 0
execp_icon_w = 24
execp_icon_h = 24
If you want to test it: the icons can be downloaded here
.
Last edited by ceeslans (2020-11-06 21:18:49)
Online