Getting Conky weather icons from Bleys to work [SOLVED]

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Logansfury wrote: Wed Feb 07, 2024 1:26 pm Welcome Back, Bleys :)

wetter.sh

Code: Select all

#!/bin/sh
#openweathermap RSS tool conky
#
#
# Bleys 2022
#
key="xxxxxxxxxxxxxxxxxxxxxxxxxxx" #persönlicher Key. Hier einmal Account anlegen: https://openweathermap.org/api und key erzeugen
lat="36.134452" #Längengrad der eigenen Location 
lon="-115.283180" #Breitengrad der eigenen Location

		wetter=$(curl -s 'api.openweathermap.org/data/2.5/weather?lat='$lat'&lon='$lon'&units=imperial&appid='$key 2>/dev/null)
		text=$(echo $wetter | jq -r '.weather[0].description') 
        tp=$( printf "%.1f" $(echo $wetter | jq -r '.main.temp'))
        wind=$( printf "%.1f" $(echo $wetter | jq -r '.wind.speed'))
		lf=$(echo $wetter | jq -r '.main.humidity') 
		icon=$(echo $wetter | jq -r '.weather[0].icon') 
        stadt=$(echo $wetter | jq -r '.name')
        luftdruck=$(echo $wetter | jq -r '.main.pressure')
        boeen=$(echo $wetter | jq -r '.wind.gust')
        sunrise=$(date +%l:%M%p -d @$(echo $wetter | jq -r '.sys.sunrise'))
        sunset=$(date +%l:%M%p -d @$(echo $wetter | jq -r '.sys.sunset'))
        aktualisiert=$(date +%l:%M%p)
        deg=$(echo $wetter | jq -r '.wind.deg')

echo $text','$tp','$wind','$lf','$icon','$sunrise','$sunset','$aktualisiert','$luftdruck','$kmhboeen','$deg
wetter.lua

Code: Select all

--[[
2023 Bleys


]]


require 'cairo'
require "imlib2"
home_path = os.getenv ('HOME')


function rgb_to_rgba(color,alpha)
if color == nil then color=0xFF0000 end
if alpha == nil then alpha=1 end
	return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end

function write_text(cr, x, y, text, f)
--write_text(cr, x, y, text, {})
--font attributes (Schriftattribute zuweisen oder default Werte annehmen)
      local font=f.font or "Neon 80s"
      local size=f.size or 12
      local align=f.align or 'l'
      local bold=f.bold or false
      local ital=f.italic or false
      local color=f.color or "0xffffff"
      local slant=CAIRO_FONT_SLANT_NORMAL
      if ital then slant=CAIRO_FONT_SLANT_ITALIC end
      local weight=CAIRO_FONT_WEIGHT_NORMAL
      if bold then weight=CAIRO_FONT_WEIGHT_BOLD end

--Text Size (Textgröße für die Plazierung bestimmen.)
      local x_a=0
      local y_a=0
      local te = cairo_text_extents_t:create()
      tolua.takeownership(te)
      cairo_select_font_face (cr, font, slant, weight)
      cairo_set_font_size (cr, size)
      cairo_text_extents (cr, text, te)

--Text Position
      if align=='c' then
        x_a = -(te.width/2+te.x_bearing)
        y_a = -(te.height/2+te.y_bearing)
      end
      if align=='r' then
        x_a = -(te.width+te.x_bearing)
      end

--Schadow 1 Pixel (Schatten für den Text um 1 Pixel versetzt)
      cairo_set_source_rgba(cr, rgb_to_rgba(0x000000,1))

      cairo_move_to (cr, x+1+x_a, y+1+y_a)
      cairo_show_text (cr, text)
      cairo_stroke(cr)

-- Now Text on Top (nun den Text oben drauf)
      cairo_set_source_rgba(cr, rgb_to_rgba(color,1))
      cairo_move_to (cr, x+x_a, y+y_a)
      cairo_show_text (cr, text)
      cairo_stroke(cr)
end

function mysplit (inputstr, sep)
        if sep == nil then
                sep = ","
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                table.insert(t, str)
        end
        return t
end

function fDrawImage(cr,path,xx,yy,ww,hh,arc)
    cairo_save (cr)
    local img =  cairo_image_surface_create_from_png(path)
    local w_img, h_img = cairo_image_surface_get_width(img), cairo_image_surface_get_height(img)
    cairo_translate (cr, xx, yy)
    if arc then
        cairo_rotate (cr, arc)
    end
    cairo_scale (cr, ww/w_img, hh/h_img)
    cairo_set_source_surface (cr, img, -w_img/2, -h_img/2)
    cairo_paint (cr)
    cairo_surface_destroy (img)
    collectgarbage ()
    cairo_restore (cr)
end

function conky_main()
	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)
  
	if update_num>4 then
        wetter = mysplit (conky_parse('${execi 60 sh '..home_path..'/.conky/wetter.sh}')) --1-text, 2-temperatur, 3-wind, 4-humidity,5-icon, 6-sunrise, 7-sunset,8-updated,9-air pressure,10-gust,11-deg

-- Wetter (Weather)
        if wetter[1]~=nil then
                write_text(cr, 20,20,wetter[1], {align="l", size=14, bold=true, color="0xff0000"})
                write_text(cr, 20,70,"Humidity: ", {align="l", size=12, color="0xff0000"})
                write_text(cr, 120,70,wetter[4].."%", {align="r", size=12, color="0xffffff"})
                write_text(cr, 20,86,"Air pressure: ", {align="l", size=12, color="0xff0000", font="Neon 80s"})
                write_text(cr, 100,86,wetter[9].." hPa", {size=12, color="0xffffff"})
                write_text(cr, 20,102,"Wind Spd: ",{align="l", size=12, color="0xff0000", font="Neon 80s"})
                write_text(cr, 100,102, " (Gusts: ",{size=12, color="0xff0000", font="Neon 80s"})
                write_text(cr, 82,102,wetter[3],{align="l", font="Neon 80s", size=12, color="0xffffff"})
                write_text(cr, 144,102,wetter[10],{align="l", font="Neon 80s", size=12, color="0xffffff"})
                write_text(cr, 172,102, ")", {align="l", size=12, color="0xff0000", font="Neon 80s"})
                write_text(cr, 178,102,"mph", {align="l", size=12, color="0xffffff", font="Neon 80s"})
                write_text(cr, 20,50,wetter[2].."°F", {font="Neon 80s", bold=false, size=20, align="l", color="0xffffff"})
                write_text(cr, 20,50,wetter[2].."°F", {font="Neon 80s", bold=false, size=20, align="l", color="0xffffff"})
                write_text(cr, 326,146,"updated: ", {font="Neon 80s", size=10, color = "0xff0000", align="r"})
                write_text(cr, 368,146,wetter[8], {font="Neon 80s", bold=false, size=10, align="r"})
                write_text(cr, 20,136,"Sunrise:", {align="l", font="Neon 80s", size=12, color="0xff0000"})
                write_text(cr, 20,152,"Sunset:", {align="l", font="Neon 80s", size=12, color="0xff0000"})
                write_text(cr, 64,136,wetter[6], {font="Neon 80s", size=12})
                write_text(cr, 64,152,wetter[7], {font="Neon 80s", size=12})
                write_text(cr, 20,120, "Wind Dir:", {font="Neon 80s", size=12, color="0xff0000"})
                write_text(cr, 82,120,wetter[10].."°",{align="l", font="Neon 80s", size=12, color="0xffffff"})
              --  {exec echo $(awk 'BEGIN{dir[1]="N";dir[2]="NE";dir[3]="E";dir[4]="SE";dir[5]="S";dir[6]="SW";dir[7]="W";dir[8]="NW";for(i in dir) if(i*45-45<$wetter[10] && $wetter[10]<=i*45) print dir[i]}')} > /home/logansfury/.conky/Bleys\ Weather/direction}

               fDrawImage(cr,home_path..'/.conky/wettericons/'..wetter[5]..'.png',312,40,116,80) -- Adapt path to your own paths
        end
	end

   cairo_surface_destroy(cs)
   cairo_destroy(cr)
end[/code}
[/quote]
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

OK :)

I have got my deg variable recognized as wetter[11] will add the other three as 12-14.

Image

Safari, Sogoodi!
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Bleys can you please help me with a conversion script?

I got this to convert wind degrees number into an alphabetic direction

Code: Select all

${execpi 3600 echo "$(awk 'BEGIN{dir[1]="N";dir[2]="NE";dir[3]="E";dir[4]="SE";dir[5]="S";dir[6]="SW";dir[7]="W";dir[8]="NW";for(i in dir) if(i*45-45<$wetter[10] && $wetter[10]<=i*45) print dir[i]}')"}
How could I use this in the script to apply the outcome of above to a variable I could then print onscreen along with the degree number. I would like degree and direction to both display please.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Bleys »

Logansfury wrote: Wed Feb 07, 2024 4:11 pm Bleys can you please help me with a conversion script?
this is much easier and more elegant to implement. wetter.lua, add 2 Lines after the fDrawImage line:

Code: Select all

	        local arc_deg = (2 * math.pi / 360) * wetter[11]
                fDrawImage(cr,home_path..'/.conky/wettericons/arrow.png',76,80,16,16,arc_deg)
find an arrow that suits you, name is arrow.png and place it inside Weather Icon Folder. I made a simple one with gimp:
arrow.png
arrow.png (1.79 KiB) Viewed 442 times
Screen Capture_select-area_20240207222640.jpg
Screen Capture_select-area_20240207222640.jpg (12.92 KiB) Viewed 442 times
Do not forget: As with placing, fDrawImage rotates images around the center of the image.
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Bleys wrote: Wed Feb 07, 2024 5:26 pm
Logansfury wrote: Wed Feb 07, 2024 4:11 pm Bleys can you please help me with a conversion script?
this is much easier and more elegant to implement. wetter.lua, add 2 Lines after the fDrawImage line:

Code: Select all

	        local arc_deg = (2 * math.pi / 360) * wetter[11]
                fDrawImage(cr,home_path..'/.conky/wettericons/arrow.png',76,80,16,16,arc_deg)
find an arrow that suits you, name is arrow.png and place it inside Weather Icon Folder. I made a simple one with gimp:
arrow.png

Screen Capture_select-area_20240207222640.jpg

Do not forget: As with placing, fDrawImage rotates images around the center of the image.
This does look nice, but I was hoping to get an alphabetical readout following the degrees display, such as:

Code: Select all

Wind Dir: 90° E
Koentje had a great idea, have conky launch a bash script that prints the outcome of the script to a text document, then have conky read the text document and display the result. His forte is bash however, could you please help me compose this for .lua?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 7
Level 7
Posts: 1581
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Koentje »

Logansfury wrote: Wed Feb 07, 2024 5:42 pm Koentje had a great idea, have conky launch a bash script that prints the outcome of the script to a text document, then have conky read the text document and display the result.
You're worse at explaining what you want. You said that the bash script was started by something else, not by conky. If i knew it was started by conky, then you didn't have to save it to a text file first, but just echo it to the terminal and execute the script with ${execp script}. P for PASTE output to conky.
Image
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Koentje wrote: Wed Feb 07, 2024 5:48 pm You're worse at explaining what you want.
Probably an Italian-American thing >.<

Plus pulling all nighters, my mind is a void sometimes.

Lemme see how much of this I can pull off without needing help formatting.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Logansfury wrote: Wed Feb 07, 2024 5:53 pm
Koentje wrote: Wed Feb 07, 2024 5:48 pm You're worse at explaining what you want.
Probably an Italian-American thing >.<

Plus pulling all nighters, my mind is a void sometimes.

Lemme see how much of this I can pull off without needing help formatting.
Actually I am already at a loss. I have a terminal style script to convert degrees to direction, How do I get the conky variable wetter[11]'s contents run by the script?

I have two conversion scripts to work with:

Code: Select all

wetter[11]=$(awk 'BEGIN{dir[1]="N";dir[2]="NE";dir[3]="E";dir[4]="SE";dir[5]="S";dir[6]="SW";dir[7]="W";dir[8]="NW";for(i in dir) if(i*45-45<$1 && $1<=i*45) print dir[i]}')

Code: Select all

-- degrees to direction
${execpi 3600 echo "$(awk 'BEGIN{dir[1]="N";dir[2]="NE";dir[3]="E";dir[4]="SE";dir[5]="S";dir[6]="SW";dir[7]="W";dir[8]="NW";for(i in dir) if(i*45-45<$wetter[11] && $wetter[11]<=i*45) print dir[i]}')"}
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Bleys »

Screen Capture_select-area_20240207230334.jpg
Screen Capture_select-area_20240207230334.jpg (10.57 KiB) Viewed 392 times
i'll think about it tomorrow. i'm done with the world for today ;)
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Bleys wrote: Wed Feb 07, 2024 6:04 pm Screen Capture_select-area_20240207230334.jpg

i'll think about it tomorrow. i'm done with the world for today ;)
Have a wonderful evening Bleys! That compass image is beautiful!!

If I can manage to get the alphabetic conversion done, I think I would like to use that on one linux box, and the compass you just displayed on my 2nd box :D

Perhaps tomorrow you can set me up with that image file?

Take care :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Bleys »

Ok.. I probably wouldn't have had any peace of mind until I had a solution. So then, without much description. Everything that generates the output is outlined in red.
Screen Capture_select-area_20240207235424.jpg
Addition: To cover N (North) right add this line:

Code: Select all

                if dir==17 then dir = 1 end
bevor the last write_text
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Coming along nicely. I am working with a pair of these, One closer to original for comparison:

Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Bleys »

Ups.. The arrow must be reversed. This way it points in the direction from which the wind is coming. Just rotate the Arrow 180°
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Bleys wrote: Wed Feb 07, 2024 6:56 pm Ok.. I probably wouldn't have had any peace of mind until I had a solution. So then, without much description. Everything that generates the output is outlined in red.

Screen Capture_select-area_20240207235424.jpg

Addition: To cover N (North) right add this line:

Code: Select all

                if dir==17 then dir = 1 end
bevor the last write_text
You are like unto a forum GOD :D That is exactly what I wanted thank you! I do also very much like your compass art and would like to have that sometime tomorrow for linux box #2 :)

I wish you well-deserved rest :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Image

It looks awesome to me! The arrow is pointing to SW so I'm happy. When I swapped it pointed to NE (Yes I am keeping your awesome arrow :) )
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Image

I have 2 versions of your weather conky prepared. One to possibly go in my Minimalis, the other for the other linux box, which I have formatted to make room for the compass artwork.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Hey Bleys,

When you have time please look at this. I noted in my wetter.lua that the update symbol in your conky was displaying like a rectangle with symbols in it. I went to your site with the original weather only documents, and noted you had Font Awesome as the font for that symbol. I found a font awesome download, and it has files full of symbols, but when I open it in gimp and type out its only alpha-numeric chars. Then I noticed that after loading the font, my display in text editor of wetter.lua showed the same 90 degree turning arrows forming a box as you had in your first conky pictures! However, while I have this update symbol in the .lua, it is NOT showing on the widget. Note the image below with arrows pointing to the pertinent items. Do you know what I need to do to get conky to display like my text editor does?

Image

Here is how it showed before I installed the font:
Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

I just saw something else intriguing in your work! In this conky:
Image

I note a sunrise font symbol by the 08:23 time and a sunset font symbol next to 17:03 time.

May I have the font for those please?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Bleys »

Logansfury wrote: Thu Feb 08, 2024 2:31 am
I note a sunrise font symbol by the 08:23 time and a sunset font symbol next to 17:03 time.

May I have the font for those please?
https://www.dafont.com/de/weather.font
After installing new Fonts:

Code: Select all

sudo fc-cache 
and restart conky or just reboot

I am currently traveling with my Notbook. The Compass picture will come this afternoon.
Last edited by Bleys on Thu Feb 08, 2024 5:27 am, edited 1 time in total.
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Getting Conky weather icons from Bleys to work [SOLVED]

Post by Logansfury »

Bleys wrote: Thu Feb 08, 2024 5:13 am
Logansfury wrote: Thu Feb 08, 2024 2:31 am
I note a sunrise font symbol by the 08:23 time and a sunset font symbol next to 17:03 time.

May I have the font for those please?
https://www.dafont.com/de/weather.font
After installing new Fonts:

Code: Select all

sudo fc-cache 
and restart conky or just reboot
Got em! Thank you so much! What about the Font Awesome? I downloaded one that corrected the output and showed the flowing arrows in the .lua but its still displaying as a blank rectangle on screen
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”