You are not logged in.

#1 2018-09-30 04:08:20

ethet
New Member
Registered: 2018-09-29
Posts: 4

Arrows (and cardinals) for wind direction in Conky weather

weather.png

After following the directions to get your API key sorted and your weather script working, here are some functions to have an arrow (or text) display the direction from which the wind is blowing (especially nice for cyclists). Edits to ~/.config/conky/scripts/bunsenweather.sh:

compare() {
    awk -v direction="$1" -v deg="$2" 'BEGIN {
        exit (direction '$3' deg) ? 0 : 1
    }'
}

cardinal_direction() {
    if compare $1 337.6 '>=' || compare $1 22.5 '<=';then
        cardinal="N"
        arrow=$(printf '\xe2\x86\x93')
    elif compare $1 22.6 '>=' && compare $1 67.5 '<=';then
        cardinal="NE"
        arrow=$(printf '\xe2\x86\x99')
    elif compare $1 67.6 '>=' && compare $1 123.75 '<=';then
        cardinal="E"
        arrow=$(printf '\xe2\x86\x90')
    elif compare $1 123.76 '>=' && compare $1 146.25 '<=';then
        cardinal="SE"
        arrow=$(printf '\xe2\x86\x96')
    elif compare $1 168.76 '>=' && compare $1 191.75 '<=';then
        cardinal="S"
        arrow=$(printf '\xe2\x86\x91')
    elif compare $1 213.76 '>=' && compare $1 236.25 '<=';then
        cardinal="SW"
        arrow=$(printf '\xe2\x86\x97')
    elif compare $1 258.76 '>=' && compare $1 281.25 '<=';then
        cardinal="W"
        arrow=$(printf '\xe2\x86\x92')
    else
        cardinal="NW"
        arrow=$(printf '\xe2\x86\x98')
    fi
}

After we load our gathered weather values into an array around line 141 of bunsenweather.sh, we can call our function with the wind direction as an argument to load our fancy variables:

cardinal_direction ${all[8]}

We now have two variables exposed for our script, $cardinal which holds a textual direction (N, NE, E, SE, S, SW, W, NW) and $arrow which will graphically stand in for those directions (the arrows suit my mental model of wind direction better).

For the arrows to display properly, we need a font that has all of the unicode directional arrows, e.g. DejaVu:

sudo apt-get fonts-dejavu

Our output for the above screenshot which uses the arrow for wind direction is coded like so:

printf "State of being:\${alignr}%s\nTemp:\${alignr}%s\nWind\${alignr} \${font dejavu sans:size=12}\${voffset -2}%s\${font}  at %s\nHumidity:\${alignr}%s\n" "$description" "$temperature" "$arrow" "$windspeed" "$humidity"

Note that we explicitly declare the font for the arrow alone and make it a bit larger for legibility, then use a vertical offset so that line of text remains in balance with the surrounding context.

I hope this is useful for someone.

Last edited by ethet (2018-10-05 20:04:36)

Offline

#2 2018-09-30 04:33:23

Dobbie03
Resident Metalhead
From: New Zealand
Registered: 2015-09-29
Posts: 1,964
Website

Re: Arrows (and cardinals) for wind direction in Conky weather

Man that looks really cool.


I like my Metal like my coffee.......Black!

Offline

Board footer

Powered by FluxBB