Greetiungs!
Back in post 16803 I contributed my Conky with clock, calendar, sysmon and weather. Since then I have worked a bit more on the weather unit adding moonphase and changing the source of weather data. Both the mooonphase and weather now use the post option in wget to download a php-generated webpage and then parsing it down to the desired format. Moonphase is from the Navy Observatory and weather is from the NWS from a page developed for small device access. It is necessary to modify the post data for your location. I used the LiveHTTPHeaders tool in Firefox to determine exactly what was being passed. Sometimes this is echoed in the URL that comes back. The moonphase shell script modifies the post data which can lead to some interesting access capabilities.
The moon font is 'negative' for display on a light background. Mine is dark so I have the moon phase in black laid over a full moon in light. It is also necessary to install the moon phase font.
conkyrc_weather
Code:
#==============================================================================
# conkyrc_weather
#
# by mjjohanson based on work by TeoBigusGeekus
#
#==============================================================================
background yes
update_interval 2000
double_buffer yes
no_buffers yes
text_buffer_size 2048
gap_x 44
gap_y 720
minimum_size 170 480
maximum_width 170
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 1
border_outer_margin 1
alignment tr
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
override_utf8_locale yes
use_xft yes
xftfont ubuntu:size=7
xftalpha 0.5
uppercase 20
default_color cccccc #text
color1 999999 #lines
color2 aaaaaa #icons
color3 888888 #footer
color4 666666 #moon phase
color5 444444
lua_load ~/.conky/weather/set_icon.lua
lua_load ~/.conky/weather/set_moon.lua
TEXT
${exec sh ~/.conky/weather/conky_weather.sh}
${exec sh ~/.conky/weather/conky_moon.sh}
${color1}${hr 1}${color2}
${font conkyweather:size=32}${lua_parse conky_set_icon 1}${color}${font}
${voffset -44}${goto 130}${color4}${font Moon Phases:size=32}0
${voffset -43}${goto 130}${color 000000}${lua_parse conky_set_moon}${color}${font}
${voffset -40}${goto 52}${exec sed -n '1p' ~/.conky/weather/forecast | fold -s -w 28}
${voffset 2}${goto 52}${exec sed -n '2p' ~/.conky/weather/forecast | fold -s -w 28}
${color1}${hr 1}${color2}
${font conkyweather:size=32}${lua_parse conky_set_icon 4}${color}${font}
${voffset -42}${goto 52}${exec sed -n '4p' ~/.conky/weather/forecast | fold -s -w 28}
${voffset 2}${goto 52}${exec sed -n '5p' ~/.conky/weather/forecast | fold -s -w 28}
${color1}${hr 1}${color2}
${font conkyweather:size=32}${lua_parse conky_set_icon 7}${color}${font}
${voffset -42}${goto 52}${exec sed -n '7p' ~/.conky/weather/forecast | fold -s -w 28}
${voffset 2}${goto 52}${exec sed -n '8p' ~/.conky/weather/forecast | fold -s -w 28}
${color1}${hr 1}${color2}
${font conkyweather:size=32}${lua_parse conky_set_icon 10}${color}${font}
${voffset -42}${goto 52}${exec sed -n '10p' ~/.conky/weather/forecast | fold -s -w 28}
${voffset 2}${goto 52}${exec sed -n '11p' ~/.conky/weather/forecast | fold -s -w 28}
${voffset 2}${color1}${hr 1}${color2}
${font conkyweather:size=32}${lua_parse conky_set_icon 13}${color}${font}
${voffset -42}${goto 52}${exec sed -n '13p' ~/.conky/weather/forecast | fold -s -w 28}
${voffset 2}${goto 52}${exec sed -n '14p' ~/.conky/weather/forecast | fold -s -w 28}
${color1}${hr 1}${color3}
${font ubuntu:size=6}last update ${time %e %B %Y %H:%M}
conky_weather.sh (download weather data and parse the file for display)
Code:
#!/bin/bash
# by mjjohanson
#
wget -O ~/.conky/weather/weather_data http://mobile.weather.gov/port_mp_ns.php? --post-data="select=1&CityName=Minneapolis&site=MPX&State=MN&warnzone=MNZ060" #saved as HTML file
grep -E "Tonight" <~/.conky/weather/weather_data >~/.conky/weather/forecast #put forecast line in new file
sed -i 's/<br><br><b>/\n/g' ~/.conky/weather/forecast #change code sequence to new line
sed -i 's/<\/b>.../-/g' ~/.conky/weather/forecast #change code sequence to dash
sed -i 's/<br><br><br><hr>//g' ~/.conky/weather/forecast #change code sequence to dash
sed -i '1 s/<b>//' ~/.conky/weather/forecast #delete code sequence
sed -i 's/\.\.\./ /' ~/.conky/weather/forecast #change ellipsis to space
sed -i 's/\. /\n/1' ~/.conky/weather/forecast #replace first dot with new line
sed -i 's/\.$/\n/' ~/.conky/weather/forecast #replace last dot with new line
sed -i 's/\./\\\n/g' ~/.conky/weather/forecast #change rest of dots to \ and new line
sed -i 's/\([0-9]\) percent/\1%/g' ~/.conky/weather/forecast #change percent to symbol
sed -i '/mph/!s/\([0-9]\) /\1° /g' ~/.conky/weather/forecast #add degree symbol after temp in lines
sed -i 's/\([0-9]\)\\$/\1°\\/g' ~/.conky/weather/forecast #add degree symbol after temp at end of lines with \
sed -i 's/\([0-9]\)$/\1°/g' ~/.conky/weather/forecast #add degree symbol after temp at end of lines without \
sed -i ':a; /\\$/N; s/\\\n//; ta' ~/.conky/weather/forecast #concatenate lines with trailing \
set_icon.lua (determine the appropriate weather icon)
Code:
-------------------------------------------------------------------------------
-- set_icon
-- parses weather line and returns letter of weather icon
--
function conky_set_icon(line)
local str = "${exec sed -n \'" .. line .. "\p' ~/.conky/weather/forecast}"
local text = string.lower(conky_parse(str))
if string.find(text, "tonight") then
if string.find(text, "clear") then return("A")
elseif string.find(text, "thunderstorms") then return("K")
elseif string.find(text, "partly cloudy") then return("C")
elseif string.find(text, "cloudy") then return("D")
elseif string.find(text, "scattered clouds") then return("B")
elseif string.find(text, "overcast") then return("D")
elseif string.find(text, "freezing") then return("O")
elseif string.find(text, "sleet") then return("O")
elseif string.find(text, "flurries") then return("O")
elseif string.find(text, "snow") then return("r")
elseif string.find(text, "fog") then return("0")
elseif string.find(text, "haze") then return("0")
elseif string.find(text, "rain") then return("G")
else
return("-")
end
else
if string.find(text, "clear") then return("a")
elseif string.find(text, "sunny") then return("b")
elseif string.find(text, "chance of snow") then return("o")
elseif string.find(text, "chance of flurries") then return("p")
elseif string.find(text, "chance of thunderstorms") then return("m")
elseif string.find(text, "chance of rain") then return("g")
elseif string.find(text, "sleet") then return("w")
elseif string.find(text, "freezing rain") then return("v")
elseif string.find(text, "thunderstorms") then return("n")
elseif string.find(text, "light rain") then return("g")
elseif string.find(text, "overcast") then return("f")
elseif string.find(text, "mostly cloudy") then return("d")
elseif string.find(text, "partly cloudy") then return("c")
elseif string.find(text, "cloudy") then return("e")
elseif string.find(text, "scattered clouds") then return("b")
elseif string.find(text, "fog") then return("0")
elseif string.find(text, "haze") then return("7")
elseif string.find(text, "rain") then return("i")
elseif string.find(text, "snow") then return("r")
else
return("-")
end
end
end
conky_moon.sh (grab and parse moon phase data - there is a lot of other sun and moon info available)
Code:
#!/bin/bash
# by mjjohanson
data="FFX=1&ID=Ubuntu&xxy="$(date +"%Y")"&xxm="$(date +"%m")"&xxd="$(date +"%d")"&st=MN&place=minneapolis&ZZZ=END"
wget -O ~/.conky/weather/moon_data http://aa.usno.navy.mil/cgi-bin/aa_pap.pl --post-data="$data"
grep -E "Phase of the Moon" <~/.conky/weather/moon_data >~/.conky/weather/moonphase #put moon phase line in new file
sed -i 's/^ <p>Phase.* //' ~/.conky/weather/moonphase #remove beginning of line up to phase description
set_moon.lua (selects the moon phase icon)
Code:
-------------------------------------------------------------------------------
-- set_moon
-- parses moon phase line and returns letter of moon icon
-- see http://www.dafont.com/moon-phases.font
function conky_set_moon()
local str = "${exec sed -n '1p' ~/.conky/weather/moonphase}"
local text = string.lower(conky_parse(str))
if string.find(text, "new") then return("0")
elseif string.find(text, "waxing crescent") then return("D")
elseif string.find(text, "first quarter") then return("G")
elseif string.find(text, "waxing gibbous") then return("J")
elseif string.find(text, "full") then return("@")
elseif string.find(text, "waning gibbous") then return("P")
elseif string.find(text, "last quarter") then return("T")
elseif string.find(text, "waning crescent") then return("W")
else
return("+")
end
end
Bookmarks