Last active
February 11, 2024 10:14
-
-
Save rdschmidt/3e903225d074433baaecab5e313ea9b7 to your computer and use it in GitHub Desktop.
Wetter Conky
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
lua_load Pfad anpassen an die eigenen Pfade | |
Adapt lua_load path to your own paths | |
]] | |
conky.config = { | |
-- — Conky settings | |
background = false, | |
update_interval = 1, | |
total_run_times = 0, | |
no_buffers = true, | |
-- — Window specifications with Shadow | |
own_window = true, | |
own_window_transparent = true, | |
own_window_hints = 'undecorated,sticky,skip_taskbar,skip_pager,below', | |
-- end | |
double_buffer = true, | |
minimum_width = 280, minimum_height = 140, | |
alignment = 'top_left', | |
-- — Text settings | |
use_xft = true, | |
font = 'Symbola:size=10', | |
override_utf8_locale = true, | |
gap_x = 20, | |
gap_y = 20, | |
-- Lua Load | |
lua_load = './wetter.lua', | |
lua_draw_hook_post = 'main', | |
}; | |
conky.text = [[ | |
]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
2023 Bleys | |
Wetter Bilder: https://www.deviantart.com/vclouds/art/VClouds-Weather-Icons-179152045 | |
Namen anpassen an das Original Openweather Schaem: https://openweathermap.org/weather-conditions | |
]] | |
require 'cairo' | |
--require "imlib2" | |
home_path = os.getenv ('HOME') | |
x_cw=0 | |
y_cw=0 | |
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 x=x+x_cw | |
local y=y+y_cw | |
local font=f.font or "Symbola" | |
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 | |
local weight | |
if ital then sland=1 else sland=0 end | |
if bold then weight=1 else weight=0 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 | jetzt 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) | |
local xx=xx+x_cw | |
local yy=yy+y_cw | |
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) | |
d_string="N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW" | |
directions = mysplit(d_string) | |
if update_num>4 then | |
wetter = mysplit (conky_parse('${execi 300 sh '..home_path..'/.conky/Wetter/wetter.sh}')) --1-text, 2-temperatur, 3-wind, 4-luftfeuchtigkeit, 5-icon, 6-Sonnenaufgang, 7-Sonnenuntergang,8-aktualisiert,9-luftdruck,10-boeen, 11-Richtung | |
-- Wetter | Weather | |
if wetter[1]~=nil then | |
write_text(cr, 20,20,wetter[1], {bold=true, align="l", size=12}) | |
write_text(cr, 20,60,wetter[2].."°C", {bold=true, size=32, align="l", color="0xf0f0f0"}) | |
write_text(cr, 20,80,"rF: ", {bold=true, align="l"}) | |
write_text(cr, 160,80,wetter[4].."%", {bold=true, align="r", color="0x1e90ff"}) | |
write_text(cr, 20,96,"Wind: ", {bold=true, align="l"}) | |
write_text(cr, 160,96,wetter[3].." ("..wetter[10]..") km/h", {bold=true, align="r", color="0x1e90ff"}) | |
write_text(cr, 20,112,"Luftdruck: ", {bold=true, align="l"}) | |
write_text(cr, 160,112,wetter[9].." hPa", {bold=true, align="r", color="0x1e90ff"}) | |
write_text(cr, 190,130,"🔁 ", { size=16, align="l"}) | |
write_text(cr, 210,130,wetter[8].." Uhr", {bold=true, align="l"}) | |
write_text(cr, 20,130,"⮬🟒 ", {bold=true, align="l", size=12}) | |
write_text(cr, 124,130,"🟒⮯", {bold=true, align="l", size=12}) | |
write_text(cr, 40,130,wetter[6].." --- "..wetter[7], {bold=true, align="l", color="0x1e90ff"}) | |
fDrawImage(cr,home_path..'/.conky/wettericons/'..wetter[5]..'.png',210,40,116,80) -- an eigenen Pfad anpassen | Adapt path to your own paths | |
local arc_deg = (2 * math.pi / 360) * wetter[11] | |
fDrawImage(cr,home_path..'/.conky/wettericons/arrow.png',250,92,20,20,arc_deg) | |
local deg=tonumber(wetter[11]) | |
local dir=math.floor((deg+11.25)/22.5)+1 | |
if dir==17 then dir = 1 end | |
write_text(cr, 230,96,deg.."° "..directions[dir], {bold=true, align="r", color="0x1e90ff"}) | |
end | |
end | |
cairo_surface_destroy(cs) | |
cairo_destroy(cr) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#openweathermap RSS tool conky | |
# | |
# | |
# Bleys 2022 | |
# | |
key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #persönlicher Key. Hier einmal Account anlegen: https://openweathermap.org/api und key erzeugen | |
lat="51.450832" #Längengrad der eigenen Location | |
lon="7.013056" #Breitengrad der eigenen Location | |
wetter=$(curl -s 'api.openweathermap.org/data/2.5/weather?lat='$lat'&lon='$lon'&lang=de&units=metric&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')) | |
deg=$(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')) #us Format | |
# sunset=$(date +%l:%M%p -d @$(echo $wetter | jq -r '.sys.sunset')) #us Format | |
sunrise=$(date +%H:%M -d @$(echo $wetter | jq -r '.sys.sunrise')) | |
sunset=$(date +%H:%M -d @$(echo $wetter | jq -r '.sys.sunset')) | |
aktualisiert=$(date +%k:%M) | |
kmhwind=$(echo "scale=1; ($wind*3.6+0.5)/1"|bc) | |
kmhboeen=$(echo "scale=1; ($boeen*3.6+0.5)/1"|bc) | |
echo $text','$tp','$kmhwind','$lf','$icon','$sunrise','$sunset','$aktualisiert','$luftdruck','$kmhboeen','$deg | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment