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

Post by Logansfury »

Bleys I have everything set to proper fonts, and colors, imperial values, and 12-hour time format. The beautiful images are showing perfectly.

I have taken my browser to openweathermap.org and got an hourly weather report:

Code: Select all

{"coord":{"lon":-115.2832,"lat":36.1345},"weather":[{"id":501,"main":"Rain","description":"moderate rain","icon":"10d"}],"base":"stations","main":{"temp":48.4,"feels_like":45.9,"temp_min":46.33,"temp_max":49.87,"pressure":1001,"humidity":87},"visibility":10000,"wind":{"speed":5.75,"deg":90},"rain":{"1h":1.12},"clouds":{"all":100},"dt":1707261569,"sys":{"type":2,"id":2016943,"country":"US","sunrise":1707230291,"sunset":1707268333},"timezone":-28800,"id":5512909,"name":"Spring Valley","cod":200}
I note some other values here that interest me. Could you please tell me how to add:

min temp
max temp
feels like temp
wind degrees

Thank you and I appreciate your time tremendously!
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

Post by Logansfury »

one last question how do I change the position of the weather image? I might be putting this into an 380pixel wide minimalis display and I would like the picture at the top right edge. I cant figure out how to edit this line:

Code: Select all

fDrawImage(cr,home_path..'/.conky/wettericons/'..wetter[5]..'.png',210,40,116,80)
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

Post by Bleys »

Logansfury wrote: Wed Feb 07, 2024 3:27 am one last question how do I change the position of the weather image? I might be putting this into an 380pixel wide minimalis display and I would like the picture at the top right edge. I cant figure out how to edit this line:

Code: Select all

fDrawImage(cr,home_path..'/.conky/wettericons/'..wetter[5]..'.png',210,40,116,80)
The last four parameters determine the position and size of the image: x,y,width, height
x,y is the center of the Picture, measured in the area of the Conky window
Screen Capture_select-area_20240207092510.jpg
Screen Capture_select-area_20240207092612.jpg
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

Post by Logansfury »

Bleys wrote: Wed Feb 07, 2024 4:29 am
Logansfury wrote: Wed Feb 07, 2024 3:27 am one last question how do I change the position of the weather image? I might be putting this into an 380pixel wide minimalis display and I would like the picture at the top right edge. I cant figure out how to edit this line:

Code: Select all

fDrawImage(cr,home_path..'/.conky/wettericons/'..wetter[5]..'.png',210,40,116,80)
The last four parameters determine the position and size of the image: x,y,width, height
x,y is the center of the Picture, measured in the area of the Conky window
Screen Capture_select-area_20240207092510.jpg

Screen Capture_select-area_20240207092612.jpg
Hello Bleys :)

Thank you for the explanation. I was thinking back to the boarderless image display where the first two digits were the height and width of the image halved. I will start experimenting with the location digits now.
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

Post by Bleys »

Logansfury wrote: Wed Feb 07, 2024 12:33 am
I note some other values here that interest me. Could you please tell me how to add:

min temp
max temp
feels like temp
wind degrees
if you make the api call in Firefox, you get a correct overview of the json tree structure:
Screen Capture_select-area_20240207093147.jpg
If you take this overview and the wetter.sh script next to it, you will see the structure:
Screen Capture_select-area_20240207093745.jpg
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

Post by Logansfury »

Bleys wrote: Wed Feb 07, 2024 4:38 am if you make the api call in Firefox, you get a correct overview of the json tree structure:
Holy crap, Firefox stepping up and being a hero! I see clearly from your image how you structured the code by the website info. I believe I can add parameters without hurting myself.

Stand by for progress report :D
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

Post by Logansfury »

Firefox wont let me in. The url that works on chrome is giving me a wrong longitude error but I know its right. I tried removing the negative sign and reducing the numbers after the decimal but nothing worked. I am just going to use the image you gave me to do this.
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

Post by Bleys »

Another example with forecast and several levels. [] stands for arrays:
Screen Capture_select-area_20240207095804.jpg
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

Post by Logansfury »

Thank you for the lessons :)

Here is my first pass at editing to add min max and feels like temps, and wind degrees

Code: Select all

text=$(echo $wetter | jq -r '.weather[0].description') 
        tp=$( printf "%.1f" $(echo $wetter | jq -r '.main.temp'))
        min=$( printf "%.1f" $(echo $wetter | jq -r '.main.temp_min'))
        max=$( printf "%.1f" $(echo $wetter | jq -r '.main.temp_max')
        feel=$( printf "%.1f" $(echo $wetter | jq -r '.main.feels_like'))
        wind=$( printf "%.1f" $(echo $wetter | jq -r '.wind.speed'))
        deg=$( printf "%.1f" $(echo $wetter | jq -r '.wind.deg'))
		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 +%H:%M)
        kmhwind=$(echo "scale=0; ($wind*3.6+0.5)/1"|bc)
        kmhboeen=$(echo "scale=0; ($boeen*3.6+0.5)/1"|bc)

echo $text','$tp','$min','$max','$feel','$kmhwind','$deg','$lf','$icon','$sunrise','$sunset','$aktualisiert','$luftdruck','$kmhboee
How does that look?
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

Post by Bleys »

Logansfury wrote: Wed Feb 07, 2024 5:03 am
How does that look?
hm.. Don't forget that the order of the values passed by the sh script is fixed in the LUA script. wetter[x].
You should therefore append new values and not put them in the middle

brackets are missing....
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
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

Post by Bleys »

No Problem with Las vegas Coords here:
Screen Capture_select-area_20240207101536.jpg
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

Post by Logansfury »

I had a typo I guess, I just tried again after refreshing the request info and got the firefox display that you posted.

Now, you arent going to believe this.........the conky is gone again. It was up and running, then it just disappeared from screen and now it wont come back no matter what I do. Ive shut CM2 down and restarted, rebooted the computer, and nothing, I was working on two versions of your weather display and now they are both just gone.
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

Post by Bleys »

Logansfury wrote: Wed Feb 07, 2024 5:19 am I had a typo I guess, I just tried again after refreshing the request info and got the firefox display that you posted.

Now, you arent going to believe this.........the conky is gone again. It was up and running, then it just disappeared from screen and now it wont come back no matter what I do. Ive shut CM2 down and restarted, rebooted the computer, and nothing, I was working on two versions of your weather display and now they are both just gone.
and no Errors in Terminal?

addendum: have to go now. Will be back in the Evening (German Time ;))
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

Post by Logansfury »

I've now got partial display and the terminal says line 109 is bad but I opened wetter.lua and wetterbu.lua in vsc editor and checked the specific line, nothing was wrong with it. I don't understand whats happening.

Have a great day! I'll talk with you later if youre available :)
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

Post by Logansfury »

Everything is restored and displaying again, I found a line that was cut off during pasting and incomplete.

Lookit this:

Image

If the wind is blowing 6.9 mph, gusts of 180 mph should NOT exist. 180 is in fact the wind degrees direction right now, I think your variable is grabbing the wrong information. Can you confirm when you return please?

I have added wind degrees to my widget, assigned it wetter[11] the first free option after 1-10 were assigned, but I cannot get it to display.
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

Post by Logansfury »

It appears that when the openweathermap site fails to display wind gust speeds (like it is now) wetter[10] is grabbing wind degrees instead. Ive watched it for half an hour and ever change in wind dir has been reflected in the gusts display.
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

Post by Bleys »

Logansfury wrote: Wed Feb 07, 2024 8:03 am It appears that when the openweathermap site fails to display wind gust speeds (like it is now) wetter[10] is grabbing wind degrees instead. Ive watched it for half an hour and ever change in wind dir has been reflected in the gusts display.
The values are accessed very specifically in wetter.sh. For gusts of wind "wind.gust"
If this value is actually empty, a NIL value for "gust" appears in the array

Post your wetter.sh and wetter.lua

Without seeing these I can hardly find an error....
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 »

Welcome Back, Bleys :)

wetter.sh

Code: Select all

#!/bin/sh
#openweathermap RSS tool conky
#
#
# Bleys 2022
#
key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #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}
Last edited by Logansfury on Wed Feb 07, 2024 3:59 pm, edited 1 time in total.
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 1:26 pm wetter.sh
sorry, was still busy.
The first thing I noticed: make your api key unrecognizable...

Next:
echo $text','$tp','$wind','$lf','$icon','$sunrise','$sunset','$aktualisiert','$luftdruck','$kmhboeen','$deg

must be:

Code: Select all

echo $text','$tp','$wind','$lf','$icon','$sunrise','$sunset','$aktualisiert','$luftdruck','$boeen','$deg
Last edited by Bleys on Wed Feb 07, 2024 3:58 pm, 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 »

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="xxxxxxxxxxxxxxxxxxxx" #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!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”