You are not logged in.
Hey folks!
Great work here. I like the canky-sandwich and will try to make one show vegan food recipies myself these days.
But for now I am a little unsure about the output of one of my conky lines:
I guess the last value is a little too high, right?
Apparently i have no idea what i am doing there
Anyways the code used is not mine and looks as follows. For my simple understanding of physics and electricity it looks quite right:
#!/bin/bash
##
## power
# get info of all devices: "upower -d"
V=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i voltage)
Volts=$(echo "$V" | awk '{print $2}' | cut -c 1-5)
W=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "energy-rate")
Watts=$(echo "$W" | awk '{print $2}' | cut -c 1-5)
Amps=$( echo "$(( $Watts / $Volts ))" )
echo $Watts"W "$Volts"V "$Amps"A"
What have i done wrong?
Thanks for your time,
naik --greetz
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
missing quotes?
V=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "voltage")
Offline
missing quotes?
V=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "voltage")
jeah, Thanks that changed a lot!
But unfortunately something is still off with my maths
naik@GerryTSSD[~]$ /usr/bin/power
10,60W 11,74V 74A
10,60/11,74 = 0,902896081772
so something must be really wrong with this line:
Amps=$( echo "$(( $Watts / $Volts ))" )
but i can`t see what!
UPDATE:
I got it working at least without the decimals:
Amps=$(( Watts / Volts ))
UPDATE 2:
Since there is and will be no floatpoint in bash I used the awk way and got what I need now:
Amps=$(awk '{printf("%.2f\n",$1/$2)}' <<<" $Watts $Volts ")
Thanks for your patience!
Naik --greetz
Last edited by Naik (2019-09-27 08:51:26)
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
You can use bc for decimal arithmetic in bash
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
Naik, I'd like to help you but don't have a laptop & no upower installed either.
Please add the line 'set -xv' near the top of your script, execute it once, and show us the full output.
Offline
hello
here one of my olds conkys made in 1.10 version
no player playing
audacious plying
radiotray-ng playing
conkyrcs
time & weather
conky.config = {
background = true,
use_xft = true,
font = 'Liberation Sans:size=9',
xftalpha = 1,
update_interval = 1.0,
total_run_times = 0,
own_window = true,
own_window_transparent = true,
--own_window_color 000000
own_window_argb_visual = true,
--own_window_argb_value = 250,
own_window_type = 'normal',
own_window_hints = 'undecorated,below,skip_taskbar,skip_pager',
double_buffer = true,
minimum_width = 470, minimum_height = 170,
maximum_width = 470,
text_buffer_size = 2048,
draw_shades = false,
draw_outline = false,
draw_borders = false,
draw_graph_borders = false,
default_color = 'white',
default_outline_color = 'white',
alignment = 'top_right',
gap_x = 30,
gap_y = 10,
no_buffers = true,
uppercase = false,
cpu_avg_samples = 2,
override_utf8_locale = true,
imlib_cache_flush_interval = 60,
imlib_cache_size = 10000,
-- Taille des pointillés
stippled_borders = 5,
-- Couleurs
default_color = '#ffffff',--ffd579
default_shade_color = '#333333',
default_outline_color = 'black',
lua_load = '~/.conky/lua/image.lua',
};
conky.text = [[
${execi 180 bash $HOME/1_accuweather/1_accuweather -f}
${font Liberation Sans:size=26}${alignc 20}${time %a %d %b %H:%M}${font}
${goto 70}----------------------------------------------------------------------------
${goto 30}Aujourdh'ui ${goto 110}demain\
${goto 190}${execi 3600 echo `date --date="2 day" | awk '{print $1}' | cut -c1-3`}.${execi 3600 echo `date --date="2 day" | awk '{print $2}'`}\
${goto 270}${execi 3600 echo `date --date="3 day" | awk '{print $1}' | cut -c1-3`}.${execi 3600 echo `date --date="3 day" | awk '{print $2}'`}${voffset -14}
${goto 360}${execi 3600 echo `date --date="4 day" | awk '{print $1}' | cut -c1-3`}.${execi 3600 echo `date --date="4 day" | awk '{print $2}'`}
${font conkyweather:size=30}${voffset -30}
${goto 40}${execi 600 sed -n '601p' $HOME/1_accuweather/daily_forecast}\
${goto 110}${execi 600 sed -n '602p' $HOME/1_accuweather/daily_forecast}\
${goto 190}${execi 600 sed -n '603p' $HOME/1_accuweather/daily_forecast}\
${goto 270}${execi 600 sed -n '604p' $HOME/1_accuweather/daily_forecast}\
${goto 360}${execi 600 sed -n '605p' $HOME/1_accuweather/daily_forecast}${font}
${goto 40}${texeci 600 sed -n '68p' $HOME/1_accuweather/daily_forecast}°/${texeci 600 sed -n '47p' $HOME/1_accuweather/daily_forecast}°\
${goto 110}${texeci 600 sed -n '108p' $HOME/1_accuweather/daily_forecast}°/${texeci 600 sed -n '87p' $HOME/1_accuweather/daily_forecast}°\
${goto 190}${texeci 600 sed -n '148p' $HOME/1_accuweather/daily_forecast}°/${texeci 600 sed -n '127p' $HOME/1_accuweather/daily_forecast}°\
${goto 270}${texeci 600 sed -n '188p' $HOME/1_accuweather/daily_forecast}°/${texeci 600 sed -n '167p' $HOME/1_accuweather/daily_forecast}°\
${goto 360}${texeci 600 sed -n '228p' $HOME/1_accuweather/daily_forecast}°/${texeci 600 sed -n '207p' $HOME/1_accuweather/daily_forecast}°\
${lua fDrawImage ~/.conky/diamond/pix/bg1.png 0 0 440 180 }
]];
cpu
conky.config = {
background = true,
use_xft = true,
font = 'Liberation Sans:size=9',
xftalpha = 1,
update_interval = 1.0,
total_run_times = 0,
own_window = true,
own_window_transparent = true,
--own_window_color 000000
own_window_argb_visual = true,
--own_window_argb_value = 250,
own_window_type = 'normal',
own_window_hints = 'undecorated,below,skip_taskbar,skip_pager',
double_buffer = true,
minimum_width = 470, minimum_height = 280,
maximum_width = 470,
text_buffer_size = 2048,
draw_shades = false,
draw_outline = false,
draw_borders = false,
draw_graph_borders = false,
default_color = 'white',
default_outline_color = 'white',
alignment = 'top_right',
gap_x = 00,
gap_y = 210,
no_buffers = true,
uppercase = false,
cpu_avg_samples = 2,
override_utf8_locale = true,
imlib_cache_flush_interval = 60,
imlib_cache_size = 10000,
-- Taille des pointillés
stippled_borders = 5,
-- Couleurs
default_color = '#ffffff',--ffd579
default_shade_color = '#333333',
default_outline_color = 'black',
lua_load = '~/.conky/lua/image.lua',
};
conky.text = [[
${voffset 30}${offset 50}Cpu1:${color DDF2FF} ${offset 3}${cpu cpu1}%${alignr 90}${voffset -5}${color #DBDBDB}${cpugraph cpu1 20,240 f1f1f1 DBDBDB}${color}
${voffset -3}${offset 50}CPU Step: ${alignr 80}${color DDF2FF}${freq_g} GHz${color}
${voffset 12}${offset 50}Cpu2:${color DDF2FF} ${offset 3}${cpu cpu2}%${alignr 90}${voffset -9}${color #DDF2FF}${cpugraph cpu2 20,240 f1f1f1 DBDBDB}${color}
${voffset -5}${alignc 10}---------------------------------------------------------------------------------
${voffset 15}${offset 50}RAM: ${alignr 80} $mem/${color #DDF2FF}$memmax${color}
${offset 50}${color #DDF2FF}${membar 5,340}${color}
${offset 50}Swap: ${alignr 80} $swap / ${color #DDF2FF}$swapmax${color}
${offset 50}${color #DDF2FF}${swapbar 5,340}${color}
${offset 50}ROOT:${color #DDF2FF} ${alignr 80} ${fs_free /} / ${fs_size /}
${offset 50}${fs_bar 5,340 /}${color}
${lua fDrawImage ~/.conky/diamond/pix/bg1.png 0 0 439 270}
]];
network
conky.config = {
background = true,
use_xft = true,
font = 'Liberation Sans:size=9',
xftalpha = 1,
update_interval = 1.0,
total_run_times = 0,
own_window = true,
own_window_transparent = true,
--own_window_color 000000
own_window_argb_visual = true,
--own_window_argb_value = 250,
own_window_type = 'normal',
own_window_hints = 'undecorated,below,skip_taskbar,skip_pager',
double_buffer = true,
minimum_width = 470, minimum_height = 170,
maximum_width = 470,
text_buffer_size = 2048,
draw_shades = false,
draw_outline = false,
draw_borders = false,
draw_graph_borders = false,
default_color = 'white',
default_outline_color = 'white',
alignment = 'top_right',
gap_x = 30,
gap_y = 470,
no_buffers = true,
uppercase = false,
cpu_avg_samples = 2,
override_utf8_locale = true,
imlib_cache_flush_interval = 60,
imlib_cache_size = 10000,
-- Taille des pointillés
stippled_borders = 5,
-- Couleurs
default_color = '#ffffff',--ffd579
default_shade_color = '#333333',
default_outline_color = 'black',
lua_load = '~/.conky/lua/image.lua',
};
conky.text = [[
${offset 25}${font Liberation Sans:size=11}SSID:${font} ${wireless_essid wlo1} ${goto 190}${font Liberation Sans:size=11}Sortant:${font} ${upspeed wlo1}
${offset 25}${font Liberation Sans:size=11}Bitrate:${font} ${wireless_bitrate wlo1} ${goto 190}${font Liberation Sans:size=11}Entrant:${font} ${downspeed wlo1}
${offset 25}${font Liberation Sans:size=11}Local:${font} ${addr wlo1} ${goto 190}${font Liberation Sans:size=11}Signal:${font} ${wireless_link_qual_perc wlo1}%
${lua fDrawImage ~/.conky/diamond/pix/bg1.png 0 0 440 102}
${if_match "${wireless_link_qual_perc wlo1}"<"1"} ${lua fDrawImage ~/.conky/diamond/pix/nonetwork.png 300 25 45 45}${else}
${if_match "${wireless_link_qual_perc wlo1}"<"20"}${lua fDrawImage ~/.conky/diamond/pix/networklow.png 300 25 45 45}${else}
${if_match "${wireless_link_qual_perc wlo1}"<"50"}${lua fDrawImage ~/.conky/diamond/pix/networkmid.png 300 25 45 45}${else}
${if_match "${wireless_link_qual_perc wlo1}"<"80"}${lua fDrawImage ~/.conky/diamond/pix/wlan80.png 300 25 45 45}${else}
${lua fDrawImage ~/.conky/diamond/pix/networkhigh.png 300 25 45 45}${endif}${endif}${endif}${endif}
]];
audacious
conky.config = {
background = true,
use_xft = true,
font = 'Liberation Sans:size=9',
xftalpha = 1,
update_interval = 1.0,
total_run_times = 0,
own_window = true,
own_window_transparent = true,
--own_window_color 000000
own_window_argb_visual = true,
--own_window_argb_value = 250,
own_window_type = 'normal',
own_window_hints = 'undecorated,below,skip_taskbar,skip_pager',
double_buffer = true,
minimum_width = 470, minimum_height = 280,
maximum_width = 470,
text_buffer_size = 2048,
draw_shades = false,
draw_outline = false,
draw_borders = false,
draw_graph_borders = false,
default_color = 'white',
default_outline_color = 'white',
alignment = 'top_right',
gap_x = 30,
gap_y = 580,
no_buffers = true,
uppercase = false,
cpu_avg_samples = 2,
override_utf8_locale = true,
imlib_cache_flush_interval = 60,
imlib_cache_size = 10000,
-- Taille des pointillés
stippled_borders = 5,
-- Couleurs
default_color = '#ffffff',--ffd579
default_shade_color = '#333333',
default_outline_color = 'black',
lua_load = '~/.conky/lua/image.lua',
};
conky.text = [[${if_running audacious}
${execi 3 ~/.conky/audacious/scripts/cover.sh}
${voffset -40}${font GE Inspira :size=12}
${goto 160}${execi 3 audtool current-song-tuple-data artist}${font}
${goto 160}${execi 3 audtool current-song-tuple-data title}
${goto 160}${execi 3 audtool current-song-tuple-data album}
${voffset 10}${goto 160}${execi 1 audtool current-song-output-length} ${goto 358}${execi 1 audtool current-song-length}\
${goto 184}${execbar 2, 168 expr 100 \* $(audtool --current-song-output-length-seconds) \/ $(audtool --current-song-length-seconds)}
${lua fDrawImage ~/.conky/diamond/pix/bg1.png 0 0 440 102}
${lua fDrawImage ~/.conky/audacious/audacious.png 44 14 68 70}
${else}
${if_running radiotray-ng}
${texeci 3 ~/.conky/radiotrayng/pochette.sh}${lua fDrawImage ~/.conky/diamond/pix/bg1.png 0 0 440 102}
${voffset -36}${alignc -80}${font GE Inspira:size=12}${execi 5 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}$font
${voffset 33}${alignc -20}${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.artist'}
${alignc -20}${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.title'}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}" == "RTL"} ${lua fDrawImage ~/.conky/radiotrayng/logos/rtl.png 222 32 50 50} ${else}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}" == "Hotmixradio 80"} ${lua fDrawImage ~/.conky/radiotrayng/logos/hotmix80.png 228 28 35 35} ${else}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}" == "Maxi 80"} ${lua fDrawImage ~/.conky/radiotrayng/logos/maxi80.png 230 29 35 35} ${else}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}" == "RTL2"} ${lua fDrawImage ~/.conky/radiotrayng/logos/rtl2.png 222 32 45 45} ${else}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}" == "MAGNUM LA RADIO"}${lua fDrawImage ~/.conky/radiotrayng/logos/magnumradio.png 184 26 120 40}${else}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}" == "radio swiss pop"}${lua fDrawImage ~/.conky/radiotrayng/logos/rspop.png 244 30 35 35} ${else}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.station'}" == "rfm"} ${lua fDrawImage ~/.conky/radiotrayng/logos/rfm.png 224 35 45 45} ${endif}
${endif}${endif}${endif}${endif}${endif}${endif}
${if_match "${execi 4 qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state | jq -r '.title'}" == ""}${lua fDrawImage ~/.conky/radiotrayng/logos/radio.png 30 10 78 78}
${else}
${lua fDrawImage ~/.conky/diamond/pochette.png 40 14 68 70}${endif}
${else}
${endif}
]];
@+
Linuxmint 22.1 Xia xfce & mageia 9 XFCE on ssd hp pavilion g7
Xubuntu 18.04 lts & 24.04 lts on ASUS Rog STRIX
Offline
https://forums.bunsenlabs.org/viewtopic … 916#p68916 the script still works MaDscntis.
Offline
loutch cover.sh can you share it.
${execi 3 ~/.conky/audacious/scripts/cover.sh}
Thank you.
Offline
hello
here
#!/bin/bash
# créer par Loutch le 18-04-2013
cp /tmp/audacious-temp* ~/.conky/audacious/audacious.jpg
convert ~/.conky/audacious/audacious.jpg ~/.conky/audacious/audacious.png
exit
Linuxmint 22.1 Xia xfce & mageia 9 XFCE on ssd hp pavilion g7
Xubuntu 18.04 lts & 24.04 lts on ASUS Rog STRIX
Offline
Thank you loutch
Offline
Naik, I'd like to help you but don't have a laptop & no upower installed either.
Please add the line 'set -xv' near the top of your script, execute it once, and show us the full output.
Sorry for the long time of absence, but here you go:
naik@GerryTSSD[~]$ /usr/bin/power
V=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "voltage")
++ upower -i /org/freedesktop/UPower/devices/battery_BAT0
++ grep -i voltage
+ V=' voltage: 12,225 V'
Volts=$(echo "$V" | awk '{print $2}' | cut -c 1-5)
++ echo ' voltage: 12,225 V'
++ awk '{print $2}'
++ cut -c 1-5
+ Volts=12,22
W=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -i "energy-rate")
++ upower -i /org/freedesktop/UPower/devices/battery_BAT0
++ grep -i energy-rate
+ W=' energy-rate: 30,6471 W'
Watts=$(echo "$W" | awk '{print $2}' | cut -c 1-5)
++ echo ' energy-rate: 30,6471 W'
++ awk '{print $2}'
++ cut -c 1-5
+ Watts=30,64
Amps=$(awk '{printf("%.2f\n",$1/$2)}' <<<" $Watts $Volts ")
++ awk '{printf("%.2f\n",$1/$2)}'
+ Amps=2.50
echo $Watts"W "$Volts"V "$Amps"A"
+ echo '30,64W 12,22V 2.50A'
30,64W 12,22V 2.50A
As you see the awk-approach works but is a little cumbersome in my eyes and I have a dot as delimiter for the decimals whereas the other values have -thanks to language settings- a comma.
I`d like to avoid that but don`t know how.
Thanks for now!
naik --greetz
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
^ I'm sorry I missed your edit in your last post - where you added that it works now.
I am surprised that awk recognizes the commas as decimal delimiter (is that how you call it).
But good that it works. I don't think your approach is too cumbersome. I'd probably use bc, but that's "Jacke wie Hose"...
Anyhow, I made some improvements to your script:
#!/bin/bash
##
## power
# get info of all devices: "upower -d"
data=( $(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | awk '/voltage|energy-rate/{print $2}' ) )
Amps=$(awk '{printf("%.2f\n",$1/$2)}' <<<" ${data[0]} ${data[1]} ")
echo "${data[0]:0:5}W ${data[1]:0:5}V ${Amps/./,}A"
Advantages:
calls upower only once
replace grep | awk with awk only
replace cut with bash bultin string manipulation
should be overall lighter on resources
Offline
^ I'm sorry I missed your edit in your last post - where you added that it works now.
I am surprised that awk recognizes the commas as decimal delimiter (is that how you call it).
But good that it works. I don't think your approach is too cumbersome. I'd probably use bc, but that's "Jacke wie Hose"...Anyhow, I made some improvements to your script:
#!/bin/bash ## ## power # get info of all devices: "upower -d" data=( $(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | awk '/voltage|energy-rate/{print $2}' ) ) Amps=$(awk '{printf("%.2f\n",$1/$2)}' <<<" ${data[0]} ${data[1]} ") echo "${data[0]:0:5}W ${data[1]:0:5}V ${Amps/./,}A"
Advantages:
calls upower only once
replace grep | awk with awk only
replace cut with bash bultin string manipulation
should be overall lighter on resources
Wow! This is great, Thank you very much ohnonot!
BTW: I call it decimal delimiter but I am not a native English speaker.
Naik --greetz
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
unklar i need help i install radiotray-ng with apacman -S radiotray-ng but don't display radio stations.
everytime i click nothing maybe i'm misssing something thank you.
Offline
never mind change theme and fix it anyway than you
Offline
unklar i need help i install radiotray-ng with apacman -S radiotray-ng but don't display radio stations.
everytime i click nothing maybe i'm misssing something thank you.
I don't know if I'm right...
At the moment radiotray-ng does not work either.
I had the mistake before.
If you execute radiotray-ng in the terminal, comes:
$ radiotray-ng
radiotray-ng: error while loading shared libraries: libboost_filesystem.so.1.69.0: cannot open shared object file: No such file or directory
the module is in the boost-libs package, which has been updated to 1.71
check
# lddtree `which radiotray-ng`
...
libboost_filesystem.so.1.69.0 => None
libboost_log.so.1.69.0 => None
libboost_program_options.so.1.69.0 => None
libboost_thread.so.1.69.0 => None
...
But he really wants module 1.69 8o
AND I haven't had time to worry about why this is so.
If you find a solution, gladly...
Edit: It also says here
https://aur.archlinux.org/packages/radiotray-ng
Last edited by unklar (2019-10-13 14:39:26)
Offline
Hi! I think, this is the only Conky thread on the Internet that is cool...
Showing a Conky I created that will run on a rpi4. It will use an external LCD from an old laptop with 1440x900 resolution which will run vertically (900x1440).
The original purpose of Conky was to read the weather at 3-hour intervals, but it all developed further with;
clock
date
namesday
Lunch at work
image that is updated every 5 minutes that is randomly picked from a directory of images
message
temperature and disk space on rpi4
No hardware yet, but at least the Conky is almost complete, hardcoded for 900x1440 resolution. Only lua was used to create this Conky.
Before I start the conky, a script is running to check the picture directory;
#!/bin/bash
set +e
cd /home/alexsson/Dropbox/ConkyPi/Pictures/
not_empty_jpg=`find . -name "*.jpg"`
if [ ! -z "$not_empty_jpg" ]
then
killall dropbox
mogrify -format png *.jpg
rm *.jpg
fi
new_pics=`find . -not -path '*/\.*' -type f ! -name "*resized.png"`
if [ ! -z "$new_pics" ]
then
killall dropbox
for image in $(/usr/bin/ls | grep -v '\_resized.png'); do value=`identify $image | awk '{print $3}' | sed 's/x/\n/g' | sort -n | head -1` ; scale=$(expr $value / 480) ; if [ $scale -eq 0 ] ; then scale=1 ; else : ; fi ;scale=$(expr 100 / $scale) ; mogrify -resize ${scale}% $image ; done
for file in $(/usr/bin/ls | grep -v '\_resized.png'); do mv $file ${file//.png/}_resized.png ; done
cp *_resized.png .show_pics/
sleep 10
dropboxd &
fi
This script will convert the images to proper resolutions. After this is done; the conky itself will start. Only lua was used, so I show you the lua-code (very hardcoded):
-- ###Openweather settings###
api_key = ""
city = "Uppsala"
country_code = "SE"
-- ###Colors###
background_color = "#FFFFFF"
weather_background_color = "#2E2E2E"
clock_text_background = "#2E2E2E"
weather_text_background = "#FFFFFF"
temp_text = "#FFFFFF"
circles = "#2E2E2EF"
transparency_background = 1.0
transparency_weather_background = 1.0
transparency_clock_text = 1.0
transparency_weather_icon = 1.0
transparency_weather_text = 1.0
transparency_temp_text = 1.0
transparency_circle = 1.0
--- ###Text file location
text_file = "/home/alexsson/Dropbox/ConkyPi/conkypi_text.txt"
directory = "/home/alexsson/Dropbox/ConkyPi/"
-- ###Dont change code below###
require 'cairo'
assert(os.setlocale("en_US.utf8", "numeric"))
a = {}
a['Monday'] = 'Måndag'
a['Tuesday'] = "Tisdag"
a['Wednesday'] = "Onsdag"
a['Thursday'] = "Torsdag"
a['Friday'] = "Fredag"
a['Saturday'] = "Lördag"
a['Sunday'] = "Söndag"
function hex2rgb(hex)
hex = hex:gsub("#","")
return (tonumber("0x"..hex:sub(1,2))/255), (tonumber("0x"..hex:sub(3,4))/255), tonumber(("0x"..hex:sub(5,6))/255)
end
r_background, g_background, b_background = hex2rgb(background_color)
r_weather_background, g_weather_background, b_weather_background = hex2rgb(weather_background_color)
r_clock_text, g_clock_text, b_clock_text = hex2rgb(clock_text_background)
r_weather_text, g_weather_text, b_weather_text = hex2rgb(weather_text_background)
r_temp_text, g_temp_text, b_temp_text = hex2rgb(temp_text)
r_circles, g_circles, b_circles = hex2rgb(circles)
function fix_text(text)
if string.len(text) == 1 then
new_text = "0" .. text
return new_text
else
new_text = text
return new_text
end
end
function check_hour(hour)
if tonumber(hour) >= 24 then
hour = tonumber(hour) - 24
return fix_text(tostring(hour))
else
return fix_text(tostring(hour))
end
end
function draw_function(cr)
local w,h=conky_window.width,conky_window.height
--Draw backgrounds
cairo_set_source_rgba(cr,r_background,g_background,b_background,transparency_background)
cairo_new_path(cr)
cairo_set_line_width(cr, 2)
cairo_rectangle(cr,0,0,w,h)
cairo_fill(cr);
cairo_set_source_rgba(cr,r_weather_background,g_weather_background,b_weather_background,transparency_weather_background)
cairo_rectangle(cr,w-200,0,200,h)
cairo_fill(cr)
cairo_close_path(cr)
--Draw clock widget
--Draw clock
cairo_new_path(cr)
cairo_set_source_rgba(cr,r_clock_text,g_clock_text,b_clock_text,transparency_clock_text)
cairo_set_font_size(cr, 78)
cairo_select_font_face (cr, "Overpass", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
time = conky_parse('${exec date +%R}')
ct_time = cairo_text_extents_t:create()
cairo_text_extents(cr,time,ct_time)
cairo_move_to(cr,350-ct_time.width/2,80)
cairo_show_text(cr,time)
cairo_close_path(cr)
--Draw date
cairo_new_path(cr)
cairo_set_font_size(cr, 24)
date = conky_parse('${execi 60 date "+%A, %-e %B, Week %V"}')
ct_date = cairo_text_extents_t:create()
cairo_text_extents(cr,date,ct_date)
cairo_move_to(cr,350-ct_date.width/2,80+ct_time.height)
cairo_show_text(cr,date)
cairo_close_path(cr)
--Draw namesday
cairo_new_path(cr)
cairo_set_font_size(cr, 24)
cairo_select_font_face (cr, "Z003", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL)
namesday = conky_parse('${execi 60 w3m -dump http://www.namnsdag.nu | sed -n "6p"}')
ct_namesday = cairo_text_extents_t:create()
cairo_text_extents(cr,namesday,ct_namesday)
cairo_move_to(cr,350-ct_namesday.width/2,75+ct_time.height+ct_time.height)
cairo_show_text(cr,namesday)
cairo_close_path(cr)
--Draw lunch
cairo_new_path(cr)
cairo_set_font_size(cr, 24)
cairo_select_font_face (cr, "Overpass", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
ct_lunch = cairo_text_extents_t:create()
cairo_text_extents(cr,"Lunch",ct_lunch)
cairo_move_to(cr,350-ct_lunch.width/2,75+ct_time.height+ct_time.height+ct_time.height)
cairo_show_text(cr,"Lunch")
cairo_move_to(cr,350-ct_lunch.width/2,75+ct_time.height+ct_time.height+ct_time.height+2)
cairo_rel_line_to (cr, ct_lunch.width+5, 0);
cairo_stroke(cr)
cairo_close_path(cr)
--Draw menu
cairo_new_path(cr)
cairo_set_font_size(cr, 18)
weekday = conky_parse('${execi 60 date +%A}')
fullmenu = conky_parse('${execi 60 curl -s https://restaurangheat.se/veckans-lunchmeny/ | sed \'s/.*<h3>' .. a[weekday] .. '<\\/h3>//g\' | awk -F \'</div>\' \'{print $1}\' | awk -F\'<h4><strong>\' \'{for(i=2;i<=NF;++i)print $i}\' | sed \'s/<\\/strong><\\/h4><p>.*//g\' | sed \'s/<strong>//g\' | sed \'s/<\\/strong>//g\' | sed \'s/Självklart serverar vi även vår goda bearnaisesås//g\' | sed \'s/<em><\\/p><p><\\/em><\\/h4>//g\' | grep -v -e \'^$\' | tr \'\\n\' \'_\' | sed \'s/<em><\\/em>//g\' | sed \'s/<\\/h4>//g\' | sed \'s/<\\/p><p>//g\'}')
pos = 1
for menu in fullmenu:gmatch("([^_]+)") do
cairo_new_path(cr)
ct_menu = cairo_text_extents_t:create()
cairo_text_extents(cr,menu,ct_menu)
cairo_move_to(cr,350-ct_menu.width/2,75+ct_time.height+ct_time.height+ct_time.height+28*pos+6)
cairo_show_text(cr,menu)
cairo_close_path(cr)
pos = pos + 1
end
cairo_close_path(cr)
--Draw messages
--Pic of day
--Get image and show it
cairo_new_path(cr)
conky_parse("${execi 1800 " .. directory .. "/Pictures/.commands_pictures.sh }")
get_image = conky_parse("${execi 300 /usr/bin/ls " .. directory .. "/Pictures/.show_pics/* | shuf -n 1 | xargs -n1 basename}")
cairo_save(cr)
cairo_arc (cr, 350, 720, 240, 0, 6.28)
cairo_clip (cr)
local image = cairo_image_surface_create_from_png (directory .. "/Pictures/.show_pics/" .. get_image)
local w_img = cairo_image_surface_get_width (image)
local h_img = cairo_image_surface_get_height (image)
cairo_set_source_surface (cr, image,350-w_img/2,480+240-h_img/2)
cairo_paint_with_alpha (cr, 1.0)
cairo_surface_destroy (image)
cairo_restore(cr)
cairo_close_path(cr)
--Messages of the day
--Get text from file
cairo_new_path(cr)
local f = assert(io.open(text_file, "rb"))
local content = f:read("*all")
f:close()
lines = 0
for line in content:gmatch("([^\n]+)") do
lines = lines + 1
end
pos = 120-(10*lines)+10
for line in content:gmatch("([^\n]+)") do
cairo_select_font_face (cr, "Overpass", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_source_rgba(cr,r_clock_text,g_clock_text,b_clock_text,transparency_clock_text)
cairo_set_font_size(cr, 24)
ct_message_of_day= cairo_text_extents_t:create()
cairo_text_extents(cr,line,ct_message_of_day)
cairo_move_to(cr,350-ct_message_of_day.width/2,480*2+pos)
cairo_show_text(cr,line)
pos = pos+ct_message_of_day.height+10
end
cairo_close_path(cr)
--Draw weather
cairo_new_path(cr)
cairo_set_source_rgba(cr,r_weather_text, g_weather_text, b_weather_text,transparency_weather_text)
cairo_set_font_size(cr, 24)
cairo_select_font_face (cr, "Overpass", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
ct_weather_text= cairo_text_extents_t:create()
cairo_text_extents(cr,city,ct_weather_text)
cairo_move_to(cr,w-100-ct_weather_text.width/2,20+ct_weather_text.height)
cairo_show_text(cr,city)
cairo_set_source_rgba(cr,r_weather_background,g_weather_background,b_weather_background,transparency_weather_background)
image_path = conky_parse("${execi 60 ./openweather.py --api_key " .. api_key .. " --city " .. city .. " --ccode " .. country_code .. " --get_weather_icon --three_hours_forecast}")
pos=0
for image in image_path:gmatch("([^\n]+)") do
cairo_save(cr)
local image = cairo_image_surface_create_from_png (image)
local w_img = cairo_image_surface_get_width (image)
local h_img = cairo_image_surface_get_height (image)
local scale_factor = 1
cairo_scale(cr, scale_factor, scale_factor)
cairo_set_source_surface (cr, image,w*(w/(w*scale_factor))-100*(w/(w*scale_factor))-w_img/2, 80*(h/(h*scale_factor))+pos)
cairo_paint_with_alpha (cr, 1.0)
cairo_surface_destroy (image)
cairo_restore(cr)
pos = pos+270
end
cairo_set_source_rgba(cr,r_weather_text, g_weather_text, b_weather_text,transparency_weather_text)
temperature = conky_parse("${execi 60 ./openweather.py --api_key " .. api_key .. " --city " .. city .. " --ccode " .. country_code .. " --get_temp_c --three_hours_forecast}")
pos=0
number_of_iterations = 1
for temp in temperature:gmatch("([^\n]+)") do
cairo_set_font_size(cr, 24)
cairo_select_font_face (cr, "Overpass", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD)
ct_temp= cairo_text_extents_t:create()
cairo_text_extents(cr,temp .. "˚C",ct_temp)
cairo_move_to(cr,w-100-ct_temp.width/2,270+ct_temp.height+pos)
cairo_show_text(cr,temp .. "˚C")
pos = pos + 270
number_of_iterations = number_of_iterations + 1
end
hour = tonumber(conky_parse('${execi 60 date +%H}'))
hour = check_hour(hour)
pos = 0
for i=1,(number_of_iterations-1) do
if i == 5 then
pos = pos-1
end
cairo_select_font_face (cr, "Overpass", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, 18)
ct_hour= cairo_text_extents_t:create()
cairo_text_extents(cr,hour .. ":00",ct_hour)
cairo_move_to(cr,w-100-ct_hour.width/2,300+ct_hour.height+pos)
cairo_show_text(cr,tostring(hour) .. ":00")
hour = check_hour(tonumber(hour)+3)
pos = pos + 270
end
cairo_close_path(cr)
--Draw system indicators
cairo_set_source_rgba(cr,r_circles,g_circles,b_circles,transparency_circle)
cairo_new_path(cr)
cairo_arc(cr,350-30,h-30,20,0,6.28)
cairo_fill(cr)
cairo_close_path(cr)
cairo_set_source_rgba(cr,r_temp_text,g_temp_text,b_temp_text,transparency_temp_text)
cairo_new_path(cr)
cairo_set_font_size(cr, 12)
ct_temp= cairo_text_extents_t:create()
cairo_text_extents(cr,"64˚C",ct_temp)
cairo_move_to(cr,350-ct_temp.width/2-30,h-30+ct_temp.height/2)
cairo_show_text(cr,"64˚C")
cairo_close_path(cr)
cairo_set_source_rgba(cr,r_circles,g_circles,b_circles,transparency_circle)
cairo_new_path(cr)
cairo_arc(cr,350+30,h-30,20,0,6.28)
cairo_fill(cr)
cairo_close_path(cr)
cairo_set_source_rgba(cr,r_temp_text,g_temp_text,b_temp_text,transparency_temp_text)
cairo_new_path(cr)
cairo_set_font_size(cr, 12)
ct_temp= cairo_text_extents_t:create()
cairo_text_extents(cr,"84%",ct_temp)
cairo_move_to(cr,350-ct_temp.width/2+30,h-30+ct_temp.height/2)
cairo_show_text(cr,"84%")
cairo_close_path(cr)
end
function conky_start_widgets()
local function draw_conky_function(cr)
draw_function(cr)
end
if conky_window==nil then return end
local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
local cr=cairo_create(cs)
local updates=conky_parse('${updates}')
update_num=tonumber(updates)
-- Check that Conky has been running for at least 5s
if update_num>5 then
draw_conky_function(cr)
end
cairo_surface_destroy(cs)
cairo_destroy(cr)
end
As you can see in the code, I yet have to code the temperature and disk space section, but because I dont own a rpi4 yet, I dont know which sensors and partitions it will use.
I fetch data from openweather using a python script executed within lua code. Code here: https://pastebin.com/vtUM9CFD (beware, hardcoded)
It works as intended, but I am eager to hear of improvements and suggestions!
Last edited by alexsson (2019-10-19 19:11:01)
Offline
^ very nice!
I hope that's not the only thing you use the pi for; I'm guessing not and it sounds like a good way to make use of otherwise (typical server scenario) unused options.
...so that gets me thinking, you're running Xorg solely for the conky?
PS: lunch looks nice, wheather is crap
Offline
^ very nice!
I hope that's not the only thing you use the pi for; I'm guessing not and it sounds like a good way to make use of otherwise (typical server scenario) unused options.
...so that gets me thinking, you're running Xorg solely for the conky?PS: lunch looks nice, wheather is crap
Thank you!
No, only Conky will be used with Fluxbox as WM.
Maybe, running some other things in the background.
Last edited by alexsson (2019-10-14 07:50:32)
Offline