SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#5451 2013-05-29 09:10:14

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

I'm not sure but after little searchings I've modified the doublerings.lua after line 222 I added that:

local extents=cairo_text_extents_t:create()
	tolua.takeownership(extents) 

Souvenirs Souvenirs...  big_smile

Offline

Help fund CrunchBang, donate to the project!

#5452 2013-05-29 09:54:02

lionhead
#! Junkie
From: Dagobah / Germany
Registered: 2011-01-22
Posts: 459

Re: Conky v1.9 Thread

is it possible to convert this external file into lua? i do not want to work with external files. the code should work even i forget to copy the sh-file wink

the code shows the distance (in km) to the space probe voyager1:

#! /bin/bash
wget http://voyager.jpl.nasa.gov/where/index.html -O ~/voyager.html  && 
dist=`cat voyager.html | grep "dist_1_v1 =" | awk '{print $4}' | awk 'sub("......$", "")'` 
echo $dist

Offline

#5453 2013-05-29 11:00:04

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

ragamatrix wrote:

I'm not sure but after little searchings I've modified the doublerings.lua after line 222 I added that:

local extents=cairo_text_extents_t:create()
	tolua.takeownership(extents) 

Souvenirs Souvenirs...  big_smile

Doesn't  work sad

Offline

#5454 2013-05-29 12:55:09

monkey of rage
#! Member
From: The Net.
Registered: 2013-02-27
Posts: 55

Re: Conky v1.9 Thread

Sorry to interrupt; I'm just going to submit something I learned recently, most of you probably know this.

You can monitor servers which have conky installed from local machines with the -X option via SSH.

ex:

$ ssh -X user@host
$ conky

Bang on, Crunchy.
8o

Offline

#5455 2013-05-29 15:11:23

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: Conky v1.9 Thread

ragamatrix wrote:
mr peachy wrote:

for the disappearing problem launch the conky from a terminal and then watch the output when you launch the second conky

for the memory leak problem, that can be tricky to track down
unfortunately i write my scripts quite differently to your doublerings.lua script (whispers *i hate setting tables*) lol

I did but nothing appears in the terminal of the first conky launched... Mysterious conky  8)
I've got another ring lua may be you'll prefer  this one ?
It's making xorg ram and cpu goes up and I don't know why too. The script descibes that it was modified for leaks problems.
I just show you for an expert eye.
rings.lua:

require 'cairo'

function conky_main_rings()
-- START PARAMETERS HERE
local rings_settings={
	--line1
	{
	name="cpu",
	arg="%S",
	max=100,
	xc=530,
	yc=45,
	thickness=4,
	radius=18,
	sectors=100,
 	gap_sectors=0,
	bg_colour1={{0,0xFFFFFF,0.1},{0.5,0xFFFFFF,0.4},{1,0xFFFFFF,0.1}},
	fg_colour1={{0,0x00FF00,0.1},{0.5,0x00FF00,1.0},{1,0x00FF00,0.1}},
	fg_colour2={{0,0xFF0000,0.1},{0.5,0xFF0000,1.0},{1,0xFF0000,0.1}},
	},	
}
--END OF PARAMETERS HERE

--main function

	--if conky_window==nil then return 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 cr=cairo_create(cs)

	if tonumber(conky_parse('${updates}'))>3 then
		for i in pairs(rings_settings) do
			draw_ring(cr,rings_settings[i])
		end
	end

	cairo_destroy(cr)

end

oops sorry there are settings tables  8.(  lol

wlourf writes good scripts, he has put the settings tables inside the main function which makes things much more versatile
this line is important

cairo_destroy(cr)

i have these 2 lines at the bottom of all my main functions

cairo_surface_destroy(cs)
cairo_destroy(cr)

which are there to prevent memory leaks

i couldnt tell you, without testing, where to put those lines in the first circles script.

Last edited by mrpeachy (2013-05-29 15:11:56)

Offline

#5456 2013-05-29 15:13:05

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: Conky v1.9 Thread

@ragamatrix - it is strange that you get nothing when launching your conky through the terminal... how do you launch it?

Offline

#5457 2013-05-29 15:19:32

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

mrpeachy wrote:

@ragamatrix - it is strange that you get nothing when launching your conky through the terminal... how do you launch it?

I don't understand, the problem is gone... Now it works.

Offline

#5458 2013-05-29 15:30:49

ragamatrix
#! Junkie
From: Earth
Registered: 2012-12-05
Posts: 286

Re: Conky v1.9 Thread

mr peachy wrote:

wlourf writes good scripts, he has put the settings tables inside the main function which makes things much more versatile
this line is important

cairo_destroy(cr)

i have these 2 lines at the bottom of all my main functions

cairo_surface_destroy(cs)
cairo_destroy(cr)

which are there to prevent memory leaks

i couldnt tell you, without testing, where to put those lines in the first circles script.

Thanks to have seen my leak problem.
I made another one witch "doesn't move' no leaks with this one with 'bars'
h_bars
Conky:

#==============================================================================
#                                  conkyrc_7
#
#  author  : CAYMUS
#  version : v20120420-07
#  license : Distributed under the terms of GNU GPL version 2 or later
#  Modified ragamatrix 05.29.2013 to an horizontal one
#==============================================================================

background yes
update_interval 1

cpu_avg_samples 2
net_avg_samples 2
temperature_unit celsius

double_buffer yes
no_buffers yes
text_buffer_size 2048

gap_x -45
gap_y 5
minimum_size 1150 70
#maximum_width 1155
own_window yes
own_window_type desktop
own_window_transparent yes
own_window_argb_visual yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 0
border_outer_margin 0
alignment tm

draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no

override_utf8_locale yes
use_xft yes
xftfont Mono:size=8
xftalpha 0.5
uppercase no

default_color 666666
color1 888888
color2 AAAAAA
color3 DDDDDD
color4 CC3333

lua_load ~/.conky/conky19/conky_8.lua
lua_draw_hook_pre main_bars
#lua_draw_hook_post main_box
###  LUA Settings  ###########################################################
lua_load ~/.conky/conky32/draw_bg.lua
TEXT
${lua conky_draw_bg 28 5 7 1150 50 0x333333 1}
${goto 50}${font :size=7}${color1}${execi 1000 cat /proc/cpuinfo | grep 'model name' | sed -e 's/model name.*: //'| uniq}${goto 50}${voffset 20}${font style:bold:size=8}${color1}Crunchbang $kernel
${voffset -35}${goto 275}${font :size=6}${color green2}${top name 1}${top cpu 1}%
${goto 275}${font :size=6}${color lightgray}${top name 2}${top cpu 2}%
${goto 275}${font :size=6}${color lightgray}${top name 3}${top cpu 3}%
${goto 275}${font :size=6}${color lightgray}${top name 4}${top cpu 4}%
${voffset -36}${goto 400}${font :size=6}${color ffff00}${top_mem name 1}${top_mem mem 1}%
${goto 400}${font :size=6}${color lightgray}${top_mem name 2}${top_mem mem 2}%
${goto 400}${font :size=6}${color lightgray}${top_mem name 3}${top_mem mem 3}%
${goto 400}${font :size=6}${color lightgray}${top_mem name 4}${top_mem mem 4}%
${goto 520}${voffset -43}${font style:bold:size=7}${color green2}cpu 1:${goto 665}${cpu}%
${goto 520}${voffset 15}${font style:bold:size=7}${color ffff00}mem:${goto 665}${memperc}%
${goto 730}${voffset -35}${font style:bold:size=7}${color green2}cpu 2:${goto 875}${font style:bold:size=7}${cpu cpu2}%
${goto 730}${voffset 15}${font style:bold:size=7}${color 1E90FF}HD:${goto 875}${fs_used_perc /home}%
${goto 950}${voffset -35}${font style:bold:size=7}${color ffff00}mem: $mem${color1} / $memmax 
${goto 940}${voffset 10}${color 00FFFF}DL:${goto 1080}${font style:bold:size=7}${color 00FFFF}${downspeedf eth0}Kb
${goto 940}${voffset 5}${color ffff00}UL:${goto 1080}${font style:bold:size=7}${color ffff00}${upspeedf eth0}Kb
${voffset -260}

conky_8.lua:

I like very much the lua codes from [b]wlourf[/b] who made it beautiful.
--[[ BARGRAPH WIDGET
	v2.1 by wlourf (07 Jan. 2011)
	edited by Caymus
	this widget draws a bargraph with different effects 
	http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
	
To call the script in a conky, use, before TEXT
	lua_load /path/to/the/script/bargraph.lua
	lua_draw_hook_pre main_rings
and add one line (blank or not) after TEXT

	
Parameters are :
3 parameters are mandatory
name	- the name of the conky variable to display, for example for {$cpu cpu0}, just write name="cpu"
arg		- the argument of the above variable, for example for {$cpu cpu0}, just write arg="cpu0"
		  arg can be a numerical value if name=""
max		- the maximum value the above variable can reach, for example, for {$cpu cpu0}, just write max=100
	
Optional parameters:
x,y		- coordinates of the starting point of the bar, default = middle of the conky window
cap		- end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
		  http://www.cairographics.org/samples/set_line_cap/
angle	- angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
		  set to 90 for an horizontal bar
skew_x	- skew bar around x axis, default = 0
skew_y	- skew bar around y axis, default = 0
blocks  - number of blocks to display for a bar (values >0) , default= 10
height	- height of a block, default=10 pixels
width	- width of a block, default=20 pixels
space	- space between 2 blocks, default=2 pixels
angle_bar	- this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
radius		- for cicular bars, internal radius, default=0
			  with radius, parameter width has no more effect.

Colours below are defined into braces {colour in hexadecimal, alpha}
fg_colour	- colour of a block ON, default= {0x00FF00,1}
bg_colour	- colour of a block OFF, default = {0x00FF00,0.5}
alarm		- threshold, values after this threshold will use alarm_colour colour , default=max
alarm_colour - colour of a block greater than alarm, default=fg_colour
smooth		- (true or false), create a gradient from fg_colour to bg_colour, default=false 
mid_colour	- colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
			  for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
			  3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
led_effect	- add LED effects to each block, default=no led_effect
			  if smooth=true, led_effect is not used
			  possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
			  led_effect has to be used with theses colours :
fg_led		- middle colour of a block ON, default = fg_colour
bg_led		- middle colour of a block OFF, default = bg_colour
alarm_led	- middle colour of a block > ALARM,  default = alarm_colour

reflection parameters, not avaimable for circular bars
reflection_alpha    - add a reflection effect (values from 0 to 1) default = 0 = no reflection
                      other values = starting opacity
reflection_scale    - scale of the reflection (default = 1 = height of text)
reflection_length   - length of reflection, define where the opacity will be set to zero
					  calues from 0 to 1, default =1
reflection			- position of reflection, relative to a vertical bar, default="b"
					  possibles values are : "b","t","l","r" for bottom, top, left, right
draw_me     - if set to false, text is not drawn (default = true or 1)
              it can be used with a conky string, if the string returns 1, the text is drawn :
              example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",

v1.0 (10 Feb. 2010) original release
v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value	
v1.2 (28 Feb. 2010) just renamed the widget to bargraph
v1.3 (03 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"

--      This program is free software; you can redistribute it and/or modify
--      it under the terms of the GNU General Public License as published by
--      the Free Software Foundation version 3 (GPLv3)
--     
--      This program is distributed in the hope that it will be useful,
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--      GNU General Public License for more details.
--     
--      You should have received a copy of the GNU General Public License
--      along with this program; if not, write to the Free Software
--      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
--      MA 02110-1301, USA.		

]]

require 'cairo'

----------------START OF PARAMETERS ----------
function conky_main_bars()
	local bars_settings={
		{
			name="cpu",
			arg="cpu1",
			max=100,
			alarm=80,
			bg_colour={0x00ff00,0.25},
			fg_colour={0x00ff00,1},
			alarm_colour={0xff0000,1},
			x=560,y=13,
			blocks=20,
			height=3,width=6,
			angle=90,
			smooth=true,
			cap="e",
			skew_y=15,
			mid_colour={{0.5,0xffff00,1}}
		},
		{
			name="cpu",
			arg="cpu2",
			max=100,
			alarm=80,
			bg_colour={0x00ff00,0.25},
			fg_colour={0x00ff00,1},
			alarm_colour={0xff0000,1},
			x=770,y=13,
			blocks=20,
			height=3,width=6,
			angle=90,
			smooth=true,
			cap="e",
			skew_y=15,
			mid_colour={{0.5,0xffff00,1}}
		},
		{
			name="memperc",
			arg="",
			max=100,
			alarm=80,
			bg_colour={0xffff00,0.25},
			fg_colour={0x00ff00,1},
			alarm_colour={0xff0000,1},
			x=560,y=39,
			blocks=20,
			height=3,width=6,
			angle=90,
			smooth=true,
			cap="e",
			skew_y=15,
			mid_colour={{0.5,0xffff00,1}}
		},
		
		{
			name="fs_used_perc",
			arg="/home",
			max=100,
			alarm=80,
			bg_colour={0x00FFFF,0.25},
			fg_colour={0x1E90FF,1},
			alarm_colour={0xff0000,1},
			x=770,y=39,
			blocks=20,
			height=3,width=6,
			angle=90,
			smooth=true,
			cap="e",
			skew_y=15,
			mid_colour={{0.5,0x00FFFF,1}}
		},
		
		{
			name="downspeedf",
			arg="eth0",
			max=100,
			alarm=80,
			bg_colour={0x00FFFF,0.25},
			fg_colour={0x1E90FF,1},
			alarm_colour={0xff0000,1},
			x=970,y=34,
			blocks=20,
			height=3,width=6,
			angle=90,
			smooth=true,
			cap="e",
			skew_y=15,
			mid_colour={{0.5,0x00FFFF,1}}
		},
		{
			name="upspeedf",
			arg="eth0",
			max=100,
			alarm=80,
			bg_colour={0xffff00,0.25},
			fg_colour={0x00ff00,1},
			alarm_colour={0xff0000,1},
			x=970,y=48,
			blocks=20,
			height=3,width=6,
			angle=90,
			smooth=true,
			cap="e",
			skew_y=15,
			mid_colour={{0.5,0xffff00,1}}
		},
		
		
						
	}
	
-----------END OF PARAMETERS--------------


    
	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)
	
	cr = cairo_create(cs)    
	--prevent segmentation error when reading cpu state
    if tonumber(conky_parse('${updates}'))>3 then
        for i in pairs(bars_settings) do
        	
        	draw_multi_bar_graph(bars_settings[i])
        	
        end
    end
	cairo_destroy(cr)
	cairo_surface_destroy(cs)
	cr=nil

end



function draw_multi_bar_graph(t)
	cairo_save(cr)
	--check values
	if t.draw_me == true then t.draw_me = nil end
	if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end	
	if t.name==nil and t.arg==nil then 
		print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ") 
		return
	end
	if t.max==nil then
		print ("No maximum value defined, use 'max'")
		return
	end
	if t.name==nil then t.name="" end
	if t.arg==nil then t.arg="" end

	--set default values	
	if t.x == nil		then t.x = conky_window.width/2 end
	if t.y == nil		then t.y = conky_window.height/2 end
	if t.blocks == nil	then t.blocks=10 end
	if t.height == nil	then t.height=10 end
	if t.angle == nil 	then t.angle=0 end
	t.angle = t.angle*math.pi/180
	--line cap style
	if t.cap==nil		then t.cap = "b" end
	local cap="b"
	for i,v in ipairs({"s","r","b"}) do 
		if v==t.cap then cap=v end
	end
	local delta=0
	if t.cap=="r" or t.cap=="s" then delta = t.height end
	if cap=="s" then 	cap = CAIRO_LINE_CAP_SQUARE
	elseif cap=="r" then
		cap = CAIRO_LINE_CAP_ROUND
	elseif cap=="b" then
		cap = CAIRO_LINE_CAP_BUTT
	end
	--end line cap style
	--if t.led_effect == nil	then t.led_effect="r" end
	if t.width == nil	then t.width=20 end
	if t.space == nil	then t.space=2 end
	if t.radius == nil	then t.radius=0 end
	if t.angle_bar == nil	then t.angle_bar=0 end
	t.angle_bar = t.angle_bar*math.pi/360 --halt angle
	
	--colours
	if t.bg_colour == nil 	then t.bg_colour = {0x00FF00,0.5} end
	if #t.bg_colour~=2 		then t.bg_colour = {0x00FF00,0.5} end
	if t.fg_colour == nil 	then t.fg_colour = {0x00FF00,1} end
	if #t.fg_colour~=2 		then t.fg_colour = {0x00FF00,1} end
	if t.alarm_colour == nil 	then t.alarm_colour = t.fg_colour end
	if #t.alarm_colour~=2 		then t.alarm_colour = t.fg_colour end

	if t.mid_colour ~= nil then	
		for i=1, #t.mid_colour do    
		    if #t.mid_colour[i]~=3 then 
		    	print ("error in mid_color table")
		    	t.mid_colour[i]={1,0xFFFFFF,1} 
		    end
		end
    end
    
	if t.bg_led ~= nil and #t.bg_led~=2	then t.bg_led = t.bg_colour end
	if t.fg_led ~= nil and #t.fg_led~=2	then t.fg_led = t.fg_colour end
	if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
	
	if t.led_effect~=nil then
		if t.bg_led == nil then t.bg_led = t.bg_colour end
		if t.fg_led == nil 	then t.fg_led = t.fg_colour end
		if t.alarm_led == nil  then t.alarm_led = t.fg_led end
	end
	

	if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
	if t.smooth == nil then t.smooth = false end

	if t.skew_x == nil then 
		t.skew_x=0 
	else
		t.skew_x = math.pi*t.skew_x/180	
	end
	if t.skew_y == nil then 
		t.skew_y=0
	else
		t.skew_y = math.pi*t.skew_y/180	
	end
	
	if t.reflection_alpha==nil then t.reflection_alpha=0 end
	if t.reflection_length==nil then t.reflection_length=1 end
	if t.reflection_scale==nil then t.reflection_scale=1 end
	
	--end of default values
	

 	local function rgb_to_r_g_b(col_a)
		return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
	end
	
	
	--functions used to create patterns

	local function create_smooth_linear_gradient(x0,y0,x1,y1)
		local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
		cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
		cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
		if t.mid_colour ~=nil then
			for i=1, #t.mid_colour do
				cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
			end
		end
		return pat
	end

	local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
		local pat =  cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
		cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
		cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
		if t.mid_colour ~=nil then
			for i=1, #t.mid_colour do
				cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
			end
		end
		return pat
	end
	
	local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
		local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
		cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
		cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
		cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
		return pat
	end

	local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
		local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
		if mode==3 then
			cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))				
			cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
			cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))				
		else
			cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
			cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))				
		end
		return pat
	end






	local function draw_single_bar()
		--this fucntion is used for bars with a single block (blocks=1) but 
		--the drawing is cut in 3 blocks : value/alarm/background
		--not zvzimzblr for circular bar
		local function create_pattern(col_alp,col_led,bg)
			local pat
			
			if not t.smooth then
				if t.led_effect=="e" then
					pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
				elseif t.led_effect=="a" then
					pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
				elseif  t.led_effect=="r" then
					pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
				else
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
				end
			else
				if bg then
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
				else
					pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
				end
			end
			return pat
		end
		
		local y1=-t.height*pct/100
		local y2,y3
		if pct>(100*t.alarm/t.max) then 
			y1 = -t.height*t.alarm/100
			y2 = -t.height*pct/100
			if t.smooth then y1=y2 end
		end
		
		if t.angle_bar==0 then
		
			--block for fg value
			local pat = create_pattern(t.fg_colour,t.fg_led,false)
			cairo_set_source(cr,pat)
			cairo_rectangle(cr,0,0,t.width,y1)
			cairo_fill(cr)
			cairo_pattern_destroy(pat)
		
			-- block for alarm value			
			if not t.smooth and y2 ~=nil then 
				pat = create_pattern(t.alarm_colour,t.alarm_led,false)
				cairo_set_source(cr,pat)
				cairo_rectangle(cr,0,y1,t.width,y2-y1)
				cairo_fill(cr)
				y3=y2
				cairo_pattern_destroy(pat)
			else
				y2,y3=y1,y1
			end
			-- block for bg value
			cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
			pat = create_pattern(t.bg_colour,t.bg_led,true)
			cairo_set_source(cr,pat)
			cairo_pattern_destroy(pat)
			cairo_fill(cr)
		end		
	end  --end single bar
	





	local function draw_multi_bar()
		--function used for bars with 2 or more blocks
		for pt = 1,t.blocks do 
			--set block y
			local y1 = -(pt-1)*(t.height+t.space)
			local light_on=false
			
			--set colors
			local col_alp = t.bg_colour
			local col_led = t.bg_led
			if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
				if pct>=(pcb*(pt-1))  then 
					light_on = true
					col_alp = t.fg_colour
					col_led = t.fg_led
					if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then 
						col_alp = t.alarm_colour 
						col_led = t.alarm_led 
					end
				end
			end

			--set colors
			--have to try to create gradients outside the loop ?
			local pat 
			
			if not t.smooth then
				if t.angle_bar==0 then
					if t.led_effect=="e" then
						pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
					elseif t.led_effect=="a" then
						pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)					
					elseif  t.led_effect=="r" then
						pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)	
					else
						pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))
					end
				else
					 if t.led_effect=="a"  then
						 pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
														 0, 0, t.radius+(t.height+t.space)*(pt),						 
											 col_alp,col_led,3)	
					else
						pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(col_alp))					
					end
					
				end
			else
				
				if light_on then
					if t.angle_bar==0 then
						pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
					else
						pat = create_smooth_radial_gradient(0, 0, (t.height+t.space),  0,0,(t.blocks+1)*(t.height+t.space),2)
					end
				else		
					pat = cairo_pattern_create_rgba  (rgb_to_r_g_b(t.bg_colour))
				end
			end
			cairo_set_source (cr, pat)
			cairo_pattern_destroy(pat)

			--draw a block
			if t.angle_bar==0 then
				cairo_move_to(cr,0,y1)
				cairo_line_to(cr,t.width,y1)
			else		
				cairo_arc( cr,0,0,
					t.radius+(t.height+t.space)*(pt)-t.height/2,
					 -t.angle_bar -math.pi/2 ,
					 t.angle_bar -math.pi/2)
			end
			cairo_stroke(cr)
		end	
	end
	
	
	
	
	local function setup_bar_graph()
		--function used to retrieve the value to display and to set the cairo structure
		if t.blocks ~=1 then t.y=t.y-t.height/2 end
		
		local value = 0
		if t.name ~="" then
			value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
			--$to_bytes doesn't work when value has a decimal point,
			--https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
			--http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
			--conky bug?
			--value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
			--if string.match(value,"%w") then
			--	value = conky_parse(string.format('${to_bytes %s}',value))
			--end
		else
			value = tonumber(t.arg)
		end

		if value==nil then value =0 end
		
		pct = 100*value/t.max
		pcb = 100/t.blocks
		
		cairo_set_line_width (cr, t.height)
		cairo_set_line_cap  (cr, cap)
		cairo_translate(cr,t.x,t.y)
		cairo_rotate(cr,t.angle)

		local matrix0 = cairo_matrix_t:create()
		tolua.takeownership(matrix0)
		cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
		cairo_transform(cr,matrix0)

	
		
		--call the drawing function for blocks
		if t.blocks==1 and t.angle_bar==0 then
			draw_single_bar()
			if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
		else
			draw_multi_bar()
		end

		--dot for reminder
		--[[
		if t.blocks ~=1 then
			cairo_set_source_rgba(cr,1,0,0,1)
			cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
			cairo_fill(cr)
		else
			cairo_set_source_rgba(cr,1,0,0,1)
			cairo_arc(cr,0,0,3,0,2*math.pi)
			cairo_fill(cr)
		end]]
		
		--call the drawing function for reflection and prepare the mask used		
		if t.reflection_alpha>0 and t.angle_bar==0 then
			local pat2
			local matrix1 = cairo_matrix_t:create()
			tolua.takeownership(matrix1)
			if t.angle_bar==0 then
				pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
				if t.reflection=="t" then
					cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
					pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
				elseif t.reflection=="r" then
					cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
					pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
				elseif t.reflection=="l" then
					cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
					pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
				else --bottom
					cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
					pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
				end
			end
			cairo_transform(cr,matrix1)

			if t.blocks==1 and t.angle_bar==0 then
				draw_single_bar()
				cairo_translate(cr,0,-t.height/2) 
			else
				draw_multi_bar()
			end
			
			
			cairo_set_line_width(cr,0.01)
			cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
			cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
			if t.angle_bar==0 then
				cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
			end
			cairo_clip_preserve(cr)
			cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
			cairo_stroke(cr)
			cairo_mask(cr,pat2)
			cairo_pattern_destroy(pat2)
			cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
			
		end --reflection
		pct,pcb=nil
	end --setup_bar_graph()
	
	--start here !
	setup_bar_graph()
	cairo_restore(cr)
end

function conky_main_box()

    if conky_window==nil then return end
    
	---------------------- PARAMETERS BEGIN HERE
    local boxes_settings={
	{x=0,y=50,w=200,h=60, corners={ {"circle",10} },colour={ {0,0x1F1F1F,0.5} },operator="atop" } ,
	{x=0,y=195,w=200,h=60, corners={ {"circle",10} },colour={ {0,0x1F1F1F,0.5} },operator="atop" } ,
	{x=0,y=320,w=200,h=60, corners={ {"circle",10} },colour={ {0,0x1F1F1F,0.5} },operator="atop" } ,
	{x=0,y=410,w=200,h=60, corners={ {"circle",10} },colour={ {0,0x1F1F1F,0.5} },operator="atop" } ,
	{x=0,y=520,w=200,h=60, corners={ {"circle",10} },colour={ {0,0x1F1F1F,0.5} },operator="atop" } ,
	{x=0,y=615,w=200,h=150, corners={ {"circle",10} },colour={ {0,0x1F1F1F,0.5} },operator="atop" } ,
    }


    ---------------------------- PARAMETERS END HERE
    
    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)
    
    if tonumber(conky_parse("$updates"))<5 then return end
    for i in pairs(boxes_settings) do
        draw_box (cr,boxes_settings[i])
    end
    cairo_destroy(cr)
    cairo_surface_destroy(cs)    
end

    
function draw_box(cr,t)

	if t.draw_me == true then t.draw_me = nil end
	if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end	

    local table_corners={"circle","curve","line"}

    local t_operators={
        clear   = CAIRO_OPERATOR_CLEAR,
        source  = CAIRO_OPERATOR_SOURCE,
        over    = CAIRO_OPERATOR_OVER,
        ["in"]      = CAIRO_OPERATOR_IN,
        out     = CAIRO_OPERATOR_OUT,
        atop    = CAIRO_OPERATOR_ATOP,
        dest    = CAIRO_OPERATOR_DEST,
        dest_over   = CAIRO_OPERATOR_DEST_OVER,
        dest_in = CAIRO_OPERATOR_DEST_IN,
        dest_out = CAIRO_OPERATOR_DEST_OUT,
        dest_atop = CAIRO_OPERATOR_DEST_ATOP,
        xor = CAIRO_OPERATOR_XOR,
        add = CAIRO_OPERATOR_ADD,
        saturate =  CAIRO_OPERATOR_SATURATE,
    }
        
    function rgba_to_r_g_b_a(tc)
        --tc={position,colour,alpha}
        local colour = tc[2]
        local alpha = tc[3]
        return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
    end

    function table.copy(t)
      local t2 = {}
      for k,v in pairs(t) do
       t2[k] = {v[1],v[2]}
      end
      return t2
    end

    function draw_corner(num,t)
        local shape=t[1]
        local radius=t[2]
        local x,y = t[3],t[4]
        if shape=="line" then
            if num == 1 then cairo_line_to(cr,radius,0) 
                elseif num == 2 then cairo_line_to(cr,x,radius) 
                elseif num == 3 then cairo_line_to(cr,x-radius,y)
                elseif num == 4 then cairo_line_to(cr,0,y-radius)
            end
        end
        if shape=="circle" then
		    local PI = math.pi
           if num == 1 then cairo_arc(cr,radius,radius,radius,-PI,-PI/2)
                elseif num == 2 then cairo_arc(cr,x-radius,y+radius,radius,-PI/2,0)
                elseif num == 3 then cairo_arc(cr,x-radius,y-radius,radius,0,PI/2) 
                elseif num == 4 then cairo_arc(cr,radius,y-radius,radius,PI/2,-PI)
            end
        end
        if shape=="curve" then
            if num == 1 then cairo_curve_to(cr,0,radius ,0,0 ,radius,0) 
                elseif num == 2 then cairo_curve_to(cr,x-radius,0, x,y, x,radius)
                elseif num == 3 then cairo_curve_to(cr,x,y-radius, x,y, x-radius,y)
                elseif num == 4 then cairo_curve_to(cr,radius,y, x,y, 0,y-radius)
            end
        end        
    end   

    --check values and set default values
    if t.x == nil then t.x = 0 end
    if t.y == nil then t.y = 0 end
    if t.w == nil then t.w = conky_window.width end
    if t.h == nil then t.h = conky_window.height end
    if t.radius == nil then t.radius = 0 end
    if t.border == nil then t.border = 0 end
    if t.colour==nil then t.colour={{1,0xFFFFFF,0.5}} end
    if t.linear_gradient ~= nil then 
        if #t.linear_gradient ~= 4 then
            t.linear_gradient = {t.x,t.y,t.width,t.height}
        end
    end 
    if t.angle==nil then t.angle = 0 end

	if t.skew_x == nil then t.skew_x=0  end
	if t.skew_y == nil then  t.skew_y=0 end
	if t.scale_x==nil then t.scale_x=1 end
	if t.scale_y==nil then t.scale_y=1 end	
	if t.rot_x == nil then t.rot_x=0  end
	if t.rot_y == nil then  t.rot_y=0 end
    
    if t.operator == nil then t.operator = "over" end
    if (t_operators[t.operator]) == nil then
        print ("wrong operator :",t.operator)
        t.operator = "over"
    end
    
    if t.radial_gradient ~= nil then 
        if #t.radial_gradient ~= 6 then
            t.radial_gradient = {t.x,t.y,0, t.x,t.y, t.width}
        end
    end 
    
    for i=1, #t.colour do    
        if #t.colour[i]~=3 then 
            print ("error in color table")
            t.colour[i]={1,0xFFFFFF,1} 
        end
    end

    if t.corners == nil then t.corners={ {"line",0} } end
    local t_corners = {}
    local t_corners = table.copy(t.corners)
    --don't use t_corners=t.corners otherwise t.corners is altered

    --complete the t_corners table if needed
    for i=#t_corners+1,4 do    
        t_corners[i]=t_corners[#t_corners]
        local flag=false
        for j,v in pairs(table_corners) do flag=flag or (t_corners[i][1]==v) end 
        if not flag then print ("error in corners table :",t_corners[i][1]);t_corners[i][1]="curve"  end
    end

    --this way :    
    --    t_corners[1][4]=x    
    --    t_corners[2][3]=y
    --doesn't work
    t_corners[1]={t_corners[1][1],t_corners[1][2],0,0}
    t_corners[2]={t_corners[2][1],t_corners[2][2],t.w,0}
    t_corners[3]={t_corners[3][1],t_corners[3][2],t.w,t.h}    
    t_corners[4]={t_corners[4][1],t_corners[4][2],0,t.h}        

    t.no_gradient = (t.linear_gradient == nil ) and (t.radial_gradient == nil )

    cairo_save(cr)
    cairo_translate(cr, t.x, t.y)
    if t.rot_x~=0 or t.rot_y~=0 or t.angle~=0 then
        cairo_translate(cr,t.rot_x,t.rot_y)
        cairo_rotate(cr,t.angle*math.pi/180)
        cairo_translate(cr,-t.rot_x,-t.rot_y)
    end
    if t.scale_x~=1 or t.scale_y~=1 or t.skew_x~=0 or t.skew_y~=0 then
	    local matrix0 = cairo_matrix_t:create()
	    tolua.takeownership(matrix0)
	    cairo_matrix_init (matrix0, t.scale_x,math.pi*t.skew_y/180	, math.pi*t.skew_x/180	,t.scale_y,0,0)
	    cairo_transform(cr,matrix0)    
    end
    
    local tc=t_corners
    cairo_move_to(cr,tc[1][2],0)
    cairo_line_to(cr,t.w-tc[2][2],0)
    draw_corner(2,tc[2])
    cairo_line_to(cr,t.w,t.h-tc[3][2])
    draw_corner(3,tc[3])
    cairo_line_to(cr,tc[4][2],t.h)
    draw_corner(4,tc[4])
    cairo_line_to(cr,0,tc[1][2])
    draw_corner(1,tc[1])
    
    if t.no_gradient then
        cairo_set_source_rgba(cr,rgba_to_r_g_b_a(t.colour[1]))
    else
        if t.linear_gradient ~= nil then
            pat = cairo_pattern_create_linear (t.linear_gradient[1],t.linear_gradient[2],t.linear_gradient[3],t.linear_gradient[4])
        elseif t.radial_gradient ~= nil then
            pat = cairo_pattern_create_radial (t.radial_gradient[1],t.radial_gradient[2],t.radial_gradient[3],
            	t.radial_gradient[4],t.radial_gradient[5],t.radial_gradient[6])
        end
        for i=1, #t.colour do
            cairo_pattern_add_color_stop_rgba (pat, t.colour[i][1], rgba_to_r_g_b_a(t.colour[i]))
        end
        cairo_set_source (cr, pat)
        cairo_pattern_destroy(pat)
    end 
     
    cairo_set_operator(cr,t_operators[t.operator]) 

    if t.border>0 then
        cairo_close_path(cr)
        if t.dash ~= nil then cairo_set_dash(cr, t.dash, 1, 0.0) end
        cairo_set_line_width(cr,t.border)
        cairo_stroke(cr)
    else
        cairo_fill(cr)
    end

    cairo_restore(cr)
end

You must add the draw_bg.lua script I posted before...

Last edited by ragamatrix (2013-05-29 15:34:33)

Offline

#5459 2013-05-29 16:32:45

PackRat
#! Die Hard
From: USA
Registered: 2011-03-03
Posts: 1,572

Re: Conky v1.9 Thread

ragamatrix wrote:

I don't understand, the problem is gone... Now it works.

Linux in a nutshell.  8o


"It does not require many words to speak the truth." - Chief Joseph, Nez Perce tribe

Offline

#5460 2013-05-29 17:27:51

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

PackRat wrote:
ragamatrix wrote:

I don't understand, the problem is gone... Now it works.

Linux in a nutshell.  8o

Linux is like the weather ... if it doesn't work, wait five minutes.  It will!  lol  lol


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5461 2013-05-30 11:57:41

jed
#! CrunchBanger
From: Detachment 7
Registered: 2012-08-28
Posts: 200
Website

Re: Conky v1.9 Thread

Sector11 wrote:

Linux is like the weather ... if it doesn't work, wait five minutes.  It will!  lol  lol

Sounds a lot like Maine, where we've actually experienced all 4 seasons of the year in the span of an hour!


Proud user of VSDIO: Jedi!  You can download it from here...  I'm on  the web at NixNut.com!

Offline

#5462 2013-05-30 12:26:39

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

Re: Conky v1.9 Thread

Something I am working on.
UcjqjB0.png

The ones on bottom row use color filling to indicate the variable. Even in the top ones, there is an issue of text being larger than the petals. Slight adjustments are needed but those are difficult to code. So, I'll probably hand hack the placement of text :8
Also, they could do with better colouring and gradients, but that's for later.

I am not posting the code right now as it is riddled with test variables and hardcoding. If that is your cup of tea, I'll clean it up a bit and post it here.

Offline

#5463 2013-05-30 12:41:03

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

jed wrote:
Sector11 wrote:

Linux is like the weather ... if it doesn't work, wait five minutes.  It will!  lol  lol

Sounds a lot like Maine, where we've actually experienced all 4 seasons of the year in the span of an hour!

Yea, that can't be good.  Hope you get through all those "hours" without incident.  Must be getting better now though.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5464 2013-05-30 12:46:00

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

easysid wrote:

Something I am working on.

I am not posting the code right now as it is riddled with test variables and hardcoding. If that is your cup of tea, I'll clean it up a bit and post it here.

I'm still trying to figure out how to get rid of the battery "alpha" section of the first rendition ... I have no battery and now matter what I do it kills the LUA script.

You do know I'm LUA illiterate don't you?  Tweak I can do but when it comes to the math ... it's allllllllll downhill!

When you do post the code ... I'll grab it gladly  big_smile


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5465 2013-05-30 12:54:12

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

Re: Conky v1.9 Thread

Sector11 wrote:

I'm still trying to figure out how to get rid of the battery "alpha" section of the first rendition ... I have no battery and now matter what I do it kills the LUA script.

remove/comment out these lines in the main function. Or you can replace battery_percent BAT0 by variable of your choice (better if it returns a value in percent)

        -- get the battery percent
        local alpha = tonumber(conky_parse('${battery_percent BAT0}'))
        -- map the battery percent to an alpha range.
        -- following maps battery [20,100] to alpha [0,0.8]
        alpha = (alpha - 20)/100        

Also remove this line from for loop

settings_t[i].fg_color[2] = alpha --substitute the alpha of fg_color

It should work then.

Offline

#5466 2013-05-30 14:35:13

lionhead
#! Junkie
From: Dagobah / Germany
Registered: 2011-01-22
Posts: 459

Re: Conky v1.9 Thread

hello

i have a little problem. the script only shows values when the the drive is mounted.

because the harddrive is always mounted it should show the value (for example 50%) and NOT the word.

here the screenshot: abbLB3Jx.jpg

this is the code:

-- weather v9000 by mrpeachy 01/10/12; released: Feb 29, 2012
-- official update by mrpeachy
-- additional features by lionhead, arclance and dk75
-- optimize lua: http://lua-users.org/wiki/OptimizedStrRep
-- last update 29.05.2013

require 'cairo'
require 'imlib2'
local username = os.getenv("USERNAME")

--you can enter your username here in case of errors, 
--enter username in quotes like this username = "yourname"
local username = "alexander"

-- you need to translate this text
local t1="frei" -- when u use fs_free or fs_free_perc
local t2="belegt" -- when u use fs_size
local t5="gesamt" -- when u use fs_used or fs_used_perc

local t3="nicht verfügbar" -- display text when hardrive/usb-stick is unmounted
local t4="n/a" -- display text when internet connection is not avaiable

-- customize ending
local e1="byte"
local e2="kb"
local e3="mb"
local e4="gb"
local e5="tb"
local e6="%"
local e7="mhz"
local e8="ghz"
local e9="mb/s"
local e10="kb/s"
local e11="uhr"

package.path = '/home/'..username..'/.v9000_config.lua'
require '.v9000_config'

-- #####################################################################
-- ## end of translation ###############################################
-- #####################################################################

start=1
--INITIALIZE SETTINGS-- need only be run once
settings_table=weather_settings()
--##################################
--######## main function ########### 
function conky_weather()--##########
-- function to convert color into hex-code
function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function

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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
--###UNCOMMENT THE BELOW LINE TO ENABLE CPU DELAY##########################################################
--if updates>5 then--###### YOU WILL ALSO HAVE TO UNCOMMENT THE MATCHING end ON LINE 923 ####################
--#########################################################################################################
local testing=0--this setting is for script testing, if not in testing set to 0
--#########################################################################################################
--############start of timed section#######################################################################
--#########################################################################################################
local timer=(updates %tonumber(settings_table[1]))
if timer==0 or start==1 then--######
start=nil--#######################################
local web=settings_table[2]
local alert_check=settings_table[13]
print ("gathering data with curl")
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
allweatherdata=f:read("*a")
f:close()
allweatherdata=string.gsub(allweatherdata,"[\n\r]","")
testall=string.find(allweatherdata,">10 Day Forecast&nbsp")
--CHECK FOR WEATHER ALERTS
if testall~=nil and alert_check==1 then
local alert=string.find(allweatherdata,"Severe Weather Alert!")
	if alert~=nil then
	print ("getting weather alerts")
	--get alert web
	local a,b,alertchunk=string.find(allweatherdata,">Local Information</div>(.*)>Severe Weather Alert!<")
	local a,b,alertsite=string.find(alertchunk,"><a href=%p(.*)%p><img src=")
	local f=io.popen("curl --max-time 60 'http://www.intellicast.com"..alertsite.."' | sed 's/%//g'")
	alertdata=f:read("*a")
	f:close()
	alertdata=string.gsub(alertdata,"[\n\r]","")
	alerttest=string.find(alertdata,"%a")
	else
	print ("you have no weather alerts")
	alerttest=0
	end--if alert~=nil
else
print ("not checking for alerts")
alerttest=1
end--if testall and alert check
processall=1
end--of timed data gathering section
--in case curl craps up it should retry until it works
if testall==nil or  alerttest==nil then
print ("curl attempt timed out, trying again")
local web=settings_table[2]
local alert_check=settings_table[13]
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
allweatherdata=f:read("*a")
f:close()
allweatherdata=string.gsub(allweatherdata,"[\n\r]","")
testall=string.find(allweatherdata,">10 Day Forecast&nbsp")
--CHECK FOR WEATHER ALERTS
if testall~=nil and alert_check==1 then
local alert=string.find(allweatherdata,"Severe Weather Alert!")
	if alert~=nil then
	print ("getting weather alerts")
	--get alert web
	local a,b,alertchunk=string.find(allweatherdata,">Local Information</div>(.*)>Severe Weather Alert!<")
	local a,b,alertsite=string.find(alertchunk,"><a href=%p(.*)%p><img src=")
	local f=io.popen("curl --max-time 60 'http://www.intellicast.com"..alertsite.."' | sed 's/%//g'")
	alertdata=f:read("*a")
	f:close()
	alertdata=string.gsub(alertdata,"[\n\r]","")
	alerttest=string.find(alertdata,"%a")
	else
	print ("you have no weather alerts")
	alerttest=0
	end--if alert~=nil
else
print ("not checking for alerts")
alerttest=1
end--if testall and alert_check
processall=1
end--if testall==nil
--end or curl reruns
--START PROCESSING ###########################################################################
if testall~=nil and alerttest~=nil and processall==1 then
local weathericons=settings_table[3]
local con_short=settings_table[4]
local visibility_unit=settings_table[6]
local wind_mph_unit=settings_table[7]
local wind_km_unit=settings_table[8]
local wind_kts_unit=settings_table[9]
local ceiling_unit=settings_table[10]
local wind_degrees_unit=settings_table[11]
local translate=settings_table[12]
local alert_check=settings_table[13]
--LOAD TRANSLATE TABLES IF TRANSLATE SETTING = 1
	if translate==1 then
	monthshort=settings_table[21]
	monthnames=settings_table[20]
	dayhort=settings_table[19]
	daynames=settings_table[18]
	neswtext=settings_table[14]
	tsuffix=settings_table[15]
	uvindextext=settings_table[16]
	moonphases=settings_table[17]
	additional=settings_table[22]
	else--neswtext,tsuffix,uvindextext,moonphases,daynames,dayshort,monthnames,monthshort

	dayshort={Monday="Mon",Tuesday="Tue",Wednesday="Wed",Thursday="Thu",Friday="Fri",Saturday="Sat",Sunday="Sun"}
	monthshort={January="Jan",February="Feb",March="Mar",April="Apr",May="May",June="Jun",July="Jul",August="Aug",September="Sep",October="Oct",November="Nov",December="Dec"}
	end--end if translate =1
--process data tables
--intellicast to conky weather icon conversion
wimage={
wx_65="32",  -- Clear
wx_66="30",  -- Partly Cloudy
wx_67="26",  -- Cloudy
wx_68="32",  -- Clear
wx_69="28",  -- Mostly Cloudy
wx_70="20",  -- Fog
wx_71="32",  -- Clear
wx_72="21",  -- Haze
wx_73="36",  -- Hot
wx_74="14",  -- Light Snow Showers
wx_75="28",  -- Mostly Cloudy
wx_76="18",  -- Sleet
wx_77="14",  -- Light Snow Showers
wx_78="23",  -- Blustery
wx_79="05",  -- Mixed Rain and Snow
wx_80="15",  -- Drifting Snow
wx_81="15",  -- Drifting Snow
wx_82="11",  -- Light Rain
wx_83="16",  -- Snow
wx_84="00",  -- Tornado
wx_85="32",  -- Clear
wx_86="25",  -- N/A
wx_87="09",  -- Drizzle
wx_88="05",  -- Mixed Rain and Snow
wx_89="18",  -- Sleet
wx_90="18",  -- Sleet
wx_91="39",  -- Scattered Showers
wx_92="39",  -- Scattered Showers
wx_93="39",  -- Scattered Showers
wx_94="39",  -- Scattered Showers
wx_95="37",  -- Isolated Thunderstorms
wx_96="37",  -- Isolated Thunderstorms
wx_97="31",  -- Clear
wx_98="29",  -- Partly Cloudy
wx_99="27",  -- Mostly Cloudy
wx_100="47",  -- Isolated Thunderstorms
wx_101="47",  -- Isolated Thunderstorms
wx_102="33",  -- Fair
wx_103="26",  -- Cloudy
wx_104="20",  -- Fog
wx_105="45",  -- Scattered Showers
wx_106="45",  -- Scattered Showers
wx_107="11",  -- Light Rain
wx_108="46",  -- Snow Showers
wx_109="46",  -- Snow Showers
wx_110="06",  -- Mixed Rain and Sleet
wx_111="18",  -- Sleet
wx_112="06",  -- Mixed Rain and Sleet
wx_113="46",  -- Snow Showers
wx_114="46",  -- Snow Showers
wx_115="31",  -- Clear
wx_116="47",  -- Isolated Thunderstorms
}--end w image table
--convert intellicast icons to weather font
wfont={
wx_65="a",
wx_66="c",
wx_67="f",
wx_68="a",
wx_69="d",
wx_70="0",
wx_71="a",
wx_72="9",
wx_73="5",
wx_74="p",
wx_75="d",
wx_76="w",
wx_77="p",
wx_78="6",
wx_79="x",
wx_80="8",
wx_81="8",
wx_82="h",
wx_83="q",
wx_84="m",
wx_85="a",
wx_86="-",
wx_87="h",
wx_88="x",
wx_89="w",
wx_90="w",
wx_91="g",
wx_92="g",
wx_93="g",
wx_94="g",
wx_95="k",
wx_96="k",
wx_97="A",
wx_98="C",
wx_99="D",
wx_100="K",
wx_101="K",
wx_102="B",
wx_103="f",
wx_104="0",
wx_105="G",
wx_106="G",
wx_107="h",
wx_108="O",
wx_109="O",
wx_110="x",
wx_111="w",
wx_112="x",
wx_113="O",
wx_114="O",
wx_115="A",
wx_116="K",
}--end w font table
--conversion day and month tables
moonfontt={
["New"]="@",
["Full"]="=",
["First Quarter"]="T",
["Last Quarter"]="G",
["Waning Gibbous"]="D",
["Waning Crescent"]="J",
["Waxing Crescent"]="Q",
["Waxing Gibbous"]="W",
}--end of moon font table
moonicont={
["New"]=weathericons.."moon_new.png",
["Full"]=weathericons.."moon_full.png",
["First Quarter"]=weathericons.."moon_first_quarter.png",
["Last Quarter"]=weathericons.."moon_last_quarter.png",
["Waning Gibbous"]=weathericons.."moon_waning_gibbous.png",
["Waning Crescent"]=weathericons.."moon_waning_crescent.png",
["Waxing Crescent"]=weathericons.."moon_waxing_crescent.png",
["Waxing Gibbous"]=weathericons.."moon_waxing_gibbous.png",
}--end of moon icon table
windfontt={
S="9",
SSW=":",
SW=";",
WSW="<",
W="=",
WNW=">",
NW="?",
NNW="@",
N="1",
NNE="2",
NE="3",
ENE="4",
E="5",
ESE="6",
SE="7",
SSE="8"
}--end of wind direction font table
--setup tables for forecast weather
forecast_day={}
forecast_day_caps={}
forecast_day_lc={}
forecast_day_short={}
forecast_day_short_caps={}
forecast_day_short_lc={}
forecast_month={}
forecast_month_caps={}
forecast_month_lc={}
forecast_month_short={}
forecast_month_short_caps={}
forecast_month_short_lc={}
forecast_date={}
weather_icon={}
weather_font={}
high_temp={}
low_temp={}
conditions={}
conditions_caps={}
conditions_lc={}
conditions_short={}
conditions_short_caps={}
conditions_short_lc={}
sun_rise={}
sun_rise_lc={}
sun_rise_time={}
sun_rise_24={}
moon_rise={}
moon_rise_lc={}
moon_rise_time={}
moon_rise_24={}
moon_rise_ampm={}
moon_rise_ampm_lc={}
sun_set={}
sun_set_lc={}
sun_set_time={}
sun_set_24={}
moon_set={}
moon_set_lc={}
moon_set_time={}
moon_set_24={}
moon_set_ampm={}
moon_set_ampm_lc={}
humidity={}
precipitation={}
snow={}
cloud_cover={}
moon_phase={}
moon_phase_caps={}
moon_phase_lc={}
moon_font={}
moon_icon={}
wind_mph={}
wind_km={}
wind_kts={}
wind_font={}
wind_icon={}
wind_deg={}
wind_nesw={}
uv_index_num={}
uv_index_txt={}
uv_index_txt_caps={}
uv_index_txt_lc={}
--get forecast chunk --------------------------------------------------------
local a,b,allweather=string.find(allweatherdata,">10 Day Forecast&nbsp(.*)>More from Intellicast</div>")
--extract information into tables
local start=0
local f=1
while f~=nil do
--match forecast day name and date
local s,f,t=string.find(allweather,"<td colspan=\"2\"><strong>([%a,%s%d]*)</strong></td>",start)
	if t~=nil then
	--split name from month and date
	local a,b,day=string.find(t,"(%a*),%s")
	local a,b,month=string.find(t,",%s(%a*)%s")
	local a,b,date=string.find(t,"(%d*)$")
	--set day names, regular, caps, lowercase and short
	table.insert(forecast_day_short,dayshort[day])
	table.insert(forecast_day_short_caps,string.upper(dayshort[day]))
	table.insert(forecast_day_short_lc,string.lower(dayshort[day]))
		if translate==1 then
		day=daynames[day]
		else
		day=day
		end
	table.insert(forecast_day,day)
	table.insert(forecast_day_caps,string.upper(day))
	table.insert(forecast_day_lc,string.lower(day))
	--set month types
	table.insert(forecast_month_short,monthshort[month])
	table.insert(forecast_month_short_caps,string.upper(monthshort[month]))
	table.insert(forecast_month_short_lc,string.lower(monthshort[month]))
		if translate==1 then
		month=monthnames[month]
		else
		month=month
		end
	table.insert(forecast_month,month)
	table.insert(forecast_month_caps,string.upper(month))
	table.insert(forecast_month_lc,string.lower(month))
	--set date
	table.insert(forecast_date,date)
	end--if t~= nil
--intellicast weather icon match
local s,f,t=string.find(allweather,"40_white/(wx_[%d]*).png\"",start)
--convert to conkyweather icon
	if t~=nil then
	table.insert(weather_icon,weathericons..wimage[t]..".png")
	--convert to weather font
	table.insert(weather_font,wfont[t])
	end
--match conditions
local s,f,t=string.find(allweather," /><br />([%a%s%p]*)</td>",start)
	if t~=nil then
	table.insert(conditions,t)
	table.insert(conditions_caps,string.upper(t))
	table.insert(conditions_lc,string.lower(t))
	--set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	----------------------------------------------------
	table.insert(conditions_short,cons)
	table.insert(conditions_short_caps,string.upper(cons))
	table.insert(conditions_short_lc,string.lower(cons))
	end
--match high temp
local s,f,t=string.find(allweather,"\"Hi\">([%p%d]*)&deg",start)
table.insert(high_temp,t)
--match low temp
local s,f,t=string.find(allweather,"\"Lo\">([%p%d]*)&deg",start)
table.insert(low_temp,t)
--match sun rise times
local s,f,t=string.find(allweather,"Rise:</strong> (%d*:%d*%s%u%u)</td>",start)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(sun_rise_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(sun_rise,tm.." "..suf)
	table.insert(sun_rise_lc,string.lower(tm.." "..suf))
	table.insert(sun_rise_time,tm)
	end
--match sun set times
local s,f,t=string.find(allweather,"Set:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then	
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(sun_set_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(sun_set,tm.." "..suf)
	table.insert(sun_set_lc,string.lower(tm.." "..suf))
	table.insert(sun_set_time,tm)
	end
--moon rise
local s,f,t=string.find(allweather,"Rise:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(moon_rise_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(moon_rise,tm.." "..suf)
	table.insert(moon_rise_lc,string.lower(tm.." "..suf))
	table.insert(moon_rise_time,tm)
	table.insert(moon_rise_ampm,suf)
	table.insert(moon_rise_ampm_lc,string.lower(suf))
	end
--moon set
local s,f,t=string.find(allweather,"Set:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(moon_set_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(moon_set,tm.." "..suf)
	table.insert(moon_set_lc,string.lower(tm.." "..suf))
	table.insert(moon_set_time,tm)
	table.insert(moon_set_ampm,suf)
	table.insert(moon_set_ampm_lc,string.lower(suf))
	end
--match uv index
local s,f,tuv=string.find(allweather,"UV Index:</strong>%s*(%d*%s*%([%a%s]*%))%s*<br />",start)
if tuv~=nil then
	--get just number
	local a,b,unm=string.find(tuv,"(%d*)%s*%([%a%s]*%)")
	--get just text
	local a,b,utx=string.find(tuv,"%d*%s*%(([%a%s]*)%)")
	table.insert(uv_index_num,unm)
		if translate==1 then
		utx=uvindextext[utx]
		else
		utx=utx
		end
	table.insert(uv_index_txt,utx)
	table.insert(uv_index_txt_caps,string.upper(utx))
	table.insert(uv_index_txt_lc,string.lower(utx))
	end
--match humidity
local s,f,t=string.find(allweather,"Humidity:</strong> (%d*)<br />",start)
table.insert(humidity,t)
--match ppt
local s,f,t=string.find(allweather,"Precipitation:</strong> (%d*)<br />",start)
table.insert(precipitation,t)
--match snow %
local s,f,t=string.find(allweather,"Snow Probability:</strong>%s*(%d*)<br />",start)
table.insert(snow,t)
--match cloud coverage
local s,f,t=string.find(allweather,"Cloud Coverage:</strong> (%d*)<br />",start)
table.insert(cloud_cover,t)
--match moon phase
local s,f,t=string.find(allweather,"Moon Phase:</strong> ([%a%s]*) <br />",start)
--set moon phase text
	if t~= nil then
	--set moon phase font and icon
	table.insert(moon_font,moonfontt[t])
	table.insert(moon_icon,moonicont[t])
		if translate==1 then
		t=moonphases[t]
		else
		t=t
		end
	table.insert(moon_phase,t)
	table.insert(moon_phase_caps,string.upper(t))
	table.insert(moon_phase_lc,string.lower(t))
	end
--match wind speeds
local s,f,tmph=string.find(allweather,"Wind Speed:</strong> (%d*)Mph",start)
local tmph=tonumber(tmph)
table.insert(wind_mph,tmph)
local s,f,t=string.find(allweather,"Mph%s*%((%d*)Km,",start)
table.insert(wind_km,t)
local s,f,t=string.find(allweather,"Km,%s*(%d*)Kts%)",start)
table.insert(wind_kts,t)
--match wind direction
local s,f,twd=string.find(allweather,"Wind Direction:</strong> ([%d&;%s%(%a%)]*)%s*</div>",start)
	if twd~=nil then
	local a,b,tdeg=string.find(twd,"(%d*)&deg;")
	table.insert(wind_deg,tdeg)
	--match wind font and nesw   
	local a,b,tnesw=string.find(twd,"%((%a*)%)")
	table.insert(wind_font,windfontt[tnesw])
		if tmph>0 and tmph<19 then
		table.insert(wind_icon,weathericons.."green_"..string.lower(tnesw)..".png")
		elseif tmph>18 and tmph<38 then
		table.insert(wind_icon,weathericons.."yellow_"..string.lower(tnesw)..".png")
		elseif tmph>37 and tmph<64 then
		table.insert(wind_icon,weathericons.."orange_"..string.lower(tnesw)..".png")
		elseif tmph>63 then
		table.insert(wind_icon,weathericons.."green_"..string.lower(tnesw)..".png")
		elseif tmph==0 then
		table.insert(wind_icon,weathericons.."no_wind.png")
		end
		if translate==1 then
		tnesw=neswtext[tnesw]
		else
		tnesw=tnesw
		end
	table.insert(wind_nesw,tnesw)
	end
if f==nil then break end
start=f
end--while
--get location
local a,b,wl=string.find(allweatherdata,"<title>%s*Intellicast%s%p%s(.*)</title>")
weather_location=string.gsub(wl," Extended Forecast in",",")
--format now weather
--extract current data
--get now weather chunk
local a,b,nowweather=string.find(allweatherdata,">Current Conditions&nbsp(.*)>View Detailed Observations for the last<br />")
now={}
monthlong={Jan="January",Feb="February",Mar="March",Apr="April",May="May",Jun="June",Jul="July",Aug="August",Sep="September",Oct="October",Nov="November",Dec="December"}
local s,f,tnow=string.find(nowweather,"<div style=\"float:right;color:#666;\">  As of ([%d%p%a%s]*) %(Local Time%)")
local s,f,t=string.find(tnow,"(%d*%p%d*%s%a*) on")
--get time only
local a,b,ntm=string.find(t,"(%d*%p%d*)")
--get suffix only
local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
now["time_24"]=convert24(ntm,suf)
if translate==1 then
suf=tsuffix[suf]
else
suf=suf
end
now["time"]=ntm.." "..suf
now["time_lc"]=string.lower(ntm.." "..suf)
now["time_num"]=ntm
now["time_ampm"]=suf
now["time_ampm_lc"]=string.lower(suf)
--get day
local s,f,t=string.find(tnow,"on (%a*)%s%d*")
if translate==1 then
day=daynames[t]
else
day=t
end
now["day"]=day
now["day_caps"]=string.upper(day)
now["day_lc"]=string.lower(day)
--short day names
local ds=dayshort[t]
now["day_short"]=ds
now["day_short_caps"]=string.upper(ds)
now["day_short_lc"]=string.lower(ds)
--get date
local s,f,t=string.find(tnow,"%s(%d%d)%s")
now["date"]=t
--get months
local s,f,t=string.find(tnow,"%d%d%s(%a*)%s%d")
if translate==1 then
mnth=monthlong[t]
now["month_short"]=monthshort[mnth]
now["month_short_caps"]=string.upper(monthshort[mnth])
now["month_short_lc"]=string.lower(monthshort[mnth])
mnth=monthnames[mnth]
else
now["month_short"]=t
now["month_short_caps"]=string.upper(t)
now["month_short_lc"]=string.lower(t)
mnth=monthlong[t]
end
now["month"]=mnth
now["month_caps"]=string.upper(mnth)
now["month_lc"]=string.lower(mnth)
local s,f,t=string.find(tnow,"%a%a%a%s(%d%d%d%d)")
now["year"]=t
local s,f,t=string.find(nowweather,"40_white/(wx_[%d]*)%ppng%p%stitle=%p")
now["weather_icon"]=weathericons..wimage[t]..".png"
now["weather_font"]=wfont[t]
local s,f,t=string.find(nowweather,"class=%pIcon%p /> ([%a%s%p]*)%s*%s*</td>%s*<td class=%pEmpty%p>&nbsp;")
local t=t:gsub("^%s*(.-)%s*$", "%1")
now["conditions"]=t
now["conditions_caps"]=string.upper(t)
now["conditions_lc"]=string.lower(t)
--set short versions------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["conditions_short"]=cons
	now["conditions_short_caps"]=string.upper(cons)
	now["conditions_short_lc"]=string.lower(cons)
--------------------------------------------
local s,f,t=string.find(nowweather,"Temperature\">([%p%d]*)&deg")
now["temp"]=t
local s,f,t=string.find(nowweather,">Feels Like: ([%p%d]*)&deg;</a>")
now["feels_like"]=t
local s,f,t=string.find(nowweather,">Wind Chill: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["wind_chill"]=t
local s,f,t=string.find(nowweather,">Ceiling: </a></td>%s*<td>([%a%d]*)</td>")
if t~="Unl" then
local s,f,t=string.find(t,"([%d%p]*)")
tc=t..ceiling_unit
else
	if translate==1 then unlset=additional.Unl else unlset=t end
tc=unlset
end
now["ceiling"]=tc
now["ceiling_caps"]=string.upper(tc)
now["ceiling_lc"]=string.lower(tc)
--get heat index
local s,f,t=string.find(nowweather,">Heat Index: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["heat_index"]=t
--get visibility
local s,f,t=string.find(nowweather,">Visibility: </a></td>%s*<td>([%a%d%p]*)</td>")
if t~="Unl" then
local s,f,t=string.find(t,"([%d%p]*)")
tv=t..visibility_unit
else
	if translate==1 then unlset=additional.Unl else unlset=t end
tv=unlset
end
now["visibility"]=tv
now["visibility_caps"]=string.upper(tv)
--get dew point
local s,f,t=string.find(nowweather,">Dew Point: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["dew_point"]=t
--get wind speed
local s,f,t=string.find(nowweather,">Wind: </a></td>%s*<td>(%d*)mph</td>")
local tmph=tonumber(t)
now["wind_mph"]=t..wind_mph_unit
now["wind_mph_caps"]=string.upper(t..wind_mph_unit)
--convert mph to km and knots
now["wind_km"]=round(tonumber(t)*1.609)..wind_km_unit
now["wind_km_caps"]=string.upper(round(tonumber(t)*1.609)..wind_km_unit)
now["wind_kts"]=round(tonumber(t)*0.869)..wind_kts_unit
now["wind_kts_caps"]=string.upper(round(tonumber(t)*0.869)..wind_kts_unit)
local s,f,t=string.find(nowweather,">Humidity: </a></td>%s*<td>(%d*)</td>")
now["humidity"]=t
--get wind direction ------------------------
local s,f,twd=string.find(nowweather,">Direction: </a></td>%s*<td style=[%p%a]*>([%d&;%s%(%a%)]*)</td>%s*</tr>")
--check for NA
local a,b,t=string.find(twd,"(%a*)")
local tnesw=t
if tnesw~="NA" then
local a,b,t=string.find(twd,"(%d*)&deg;")
now["wind_deg"]=t..wind_degrees_unit
local a,b,tnesw=string.find(twd,"%((%a*)%)")
	if tmph>0 and tmph<19 then
	now["wind_icon"]=weathericons.."green_"..string.lower(tnesw)..".png"
	elseif tmph>18 and tmph<38 then
	now["wind_icon"]=weathericons.."yellow_"..string.lower(tnesw)..".png"
	elseif tmph>37 and tmph<64 then
	now["wind_icon"]=weathericons.."orange_"..string.lower(tnesw)..".png"
	elseif tmph>63 then
	now["wind_icon"]=weathericons.."green_"..string.lower(tnesw)..".png"
	end
now["wind_font"]=windfontt[tnesw]
	if translate==1 then
	tnesw=neswtext[tnesw]
	else
	tnesw=tnesw
	end
now["wind_nesw"]=tnesw		
else
	if translate==1 then naset=additional.NA else naset="NA" end
now["wind_deg"]=naset
now["wind_icon"]=weathericons.."no_wind.png"
now["wind_nesw"]=naset
now["wind_font"]=windfontt["N"]
end
--END WIND DIRECTION #######################################################
--get pressure
local s,f,t=string.find(nowweather,">Pressure: </a></td>%s*<td>([%d%p]*)\"</td>")
now["pressure"]=t
--convert pressures ----------------
now["pressure_mb"]=round(tonumber(t)*33.86)
local s,f,t=string.find(nowweather,">Gusts: </a></td>%s*<td>([%d%a]*)</td>")
if t~="NA" then
local s,f,t=string.find(t,"(%d*)")
tg=t..wind_mph_unit
tgkm=round(tonumber(t)*1.609)..wind_km_unit
tgkts=round(tonumber(t)*0.869)..wind_kts_unit
else
	if translate==1 then naset=additional.NA else naset="NA" end
tg=naset
tgkm=naset
tgkts=naset
end
now["wind_gusts"]=tg
now["wind_gusts_caps"]=string.upper(tg)
now["wind_gusts_km"]=tgkm
now["wind_gusts_km_caps"]=string.upper(tgkm)
now["wind_gusts_kts"]=tgkts
now["wind_gusts_kts_caps"]=string.upper(tgkts)
--get hourly forecast options hour1
--get day 1 bit
local s,f,hfc=string.find(nowweather,"<td class=%pHour%p%sstyle=%ppadding%pleft([%a%d%p%s]*)%pdeg%p</strong>",1)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",1)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",1)
--24 hour conversion
now["fc_hour1_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour1_time"]=tm
now["fc_hour1_ampm"]=suf
now["fc_hour1_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%p%s%a]*)%s*</td>%s*<td class=%pHour%p",1)
now["fc_hour1_cond"]=t
now["fc_hour1_cond_lc"]=string.lower(t)
now["fc_hour1_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour1_cond_short"]=cons
	now["fc_hour1_cond_short_caps"]=string.upper(cons)
	now["fc_hour1_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",1)
now["fc_hour1_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour1_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)&deg;</strong></td>",1)
now["fc_hour1_temp"]=t
--end of hour1 data gathering--repeat 2 more times
--get hourly forecast options hour2--------------------
local start=tonumber(b)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",start)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",start)
--24 hour conversion
now["fc_hour2_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour2_time"]=tm
now["fc_hour2_ampm"]=suf
now["fc_hour2_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%a%s%p]*)%s*</td>%s*<td class=%pHour%p",start)
now["fc_hour2_cond"]=t
now["fc_hour2_cond_lc"]=string.lower(t)
now["fc_hour2_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour2_cond_short"]=cons
	now["fc_hour2_cond_short_caps"]=string.upper(cons)
	now["fc_hour2_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",start)
now["fc_hour2_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour2_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)&deg;</strong></td>",start)
now["fc_hour2_temp"]=t
--end of hour2 data gathering--repeat 1 more times
local start=tonumber(b)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",start)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",start)
--24 hour conversion
now["fc_hour3_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour3_time"]=tm
now["fc_hour3_ampm"]=suf
now["fc_hour3_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%a%s%p]*)%s*</td>%s*<td class=%pHour%p",start)
now["fc_hour3_cond"]=t
now["fc_hour3_cond_lc"]=string.lower(t)
now["fc_hour3_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour3_cond_short"]=cons
	now["fc_hour3_cond_short_caps"]=string.upper(cons)
	now["fc_hour3_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",start)
now["fc_hour3_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour3_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)",start)
now["fc_hour3_temp"]=t
--end of hour3 data gathering--finished for all hours
--ALERTS###############################################################
if alert_check==1 then
--set tables
alert_type={}
alert_issued={}
if alerttest~=0 then
alert_icon=weathericons.."icon_alert_1.gif"
--extract information into tables
local start=0
local f=1
while f~=nil do
local s,f,t=string.find(alertdata,"><strong class='Alert'>([%a%s]*)</strong><br/>",start)
	if t~=nil then
	table.insert(alert_type,string.upper(t))
	end--if t~=nil
local s,f,t=string.find(alertdata,"<br />([%d%a%s:]*)<br /><br />",start)
	if t~=nil then
	table.insert(alert_issued,t)
	end--if t~=nil
if f==nil then break end
start=f
alert_number=#alert_type
end--while
else
alert_icon=weathericons.."icon_alert_0.gif"
table.insert(alert_type,"NO ALERTS")
table.insert(alert_issued,"")
alert_number=0
end--alerttest~=nil
else
alert_type={}
alert_issued={}
alert_icon=weathericons.."icon_alert_0.gif"
table.insert(alert_type,"alerts turned off")
table.insert(alert_issued,"")
alert_number=0
end--if alert check
-- end of data processing
if testing==0 then
processall=0
print ("processing complete")
elseif testing==1 then
processall=1
end--if testing ==0
end--of data processing section
if processall==0 or testing==1 then
_G.weather_script()
end
--#########################################################################################################
--###UNCOMMENT THE BELOW LINE TO ENABLE CPU DELAY##########################################################
--end--####### end of if updates>5 #############################
--#########################################################################################################
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

function round(num)
	local idp=tonumber(settings_table[5])
	local mult = 10^(idp or 0)
	return math.floor(num * mult + 0.5) / mult
end--of round function

function string:split(delimiter)
local result = { }
local from  = 1
local delim_from, delim_to = string.find( self, delimiter, from  )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from  = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from  )
end
table.insert( result, string.sub( self, from  ) )
return result
end--string split


function xout(txj)
c=nil
a=nil
f=nil
fs=nil
x=nil
y=nil
txt=nil
j=nil

c=(txj.c or default_color)
a=(txj.a or default_alpha)
f=(txj.f or default_font)
fs=(txj.fs or default_font_size)
x=(txj.x or 0)
y=(txj.y or 0)
txt=(txj.txt or "set txt")
j=(txj.j or "l")

local cs=txj.cs     or default_size         or "normal_c"
local format=txj.format					or default_format			or "normal"
local ul=txj.ul     or default_ul         or "no"
local shaded=txj.shaded				or default_shaded		or "no"
------------------
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
local text=string.gsub(txt," ","_")
extents=cairo_text_extents_t:create()
cairo_text_extents(cr,text,extents)
local wx=extents.width
if j=="l" then
cairo_move_to (cr,x,y)
adx=wx
elseif j=="c" then
cairo_move_to (cr,x-(wx/2),y)
adx=wx/2
elseif j=="r" then
cairo_move_to (cr,x-wx,y)
adx=0
end
------------------------------------------------------------------------
cairo_select_font_face (cr, f, font_slant(format),font_weight(format));
------------------------------------------------------------------------
if cs=="big_c" then
txt=string.upper(txt)
elseif cs=="small_c" then
txt=string.lower(txt)
elseif cs=="normal_c" then
txt=txt
end
------------------------------------------------------------------------
	if ul=="yes" then
		lw=1
		lc=CAIRO_LINE_CAP_BUTT
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE)
		----------------------------
		startx=x
		endx=startx+wx
		starty=y+5
		endy=y+5
		----------------------------
		cairo_set_line_width (cr,lw)
		cairo_set_line_cap  (cr, lc)
		cairo_set_source_rgba (cr,col(c,a))
		cairo_show_text (cr,txt)
		cairo_move_to (cr,x,starty)
		cairo_line_to (cr,x+wx,endy)
		cairo_stroke (cr)
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT) 
	elseif ul == "no" then
		txt=txt
	end -- if
	-----------------------------------------------------
	if shaded == "yes" then
		sc=0x000000
		sa=1
		cairo_move_to (cr,(x + 1),(y + 1))
		cairo_set_source_rgba (cr,col(sc,sa))
		cairo_show_text (cr,txt)
		cairo_stroke (cr)
	elseif shaded=="no" then
	txt=txt
	end
	----------------------------------------------------
cairo_move_to (cr,(x),(y))
cairo_set_source_rgba (cr,col(c,a))
cairo_show_text (cr,txt)
cairo_stroke (cr)
nextx=nil
nextx=adx+x
return nextx
end--function xout

-- all following functions are working stand-alone
-- they can be copied because they do not have any dependance to work

function out(txj) -- function to output text
	local extents=cairo_text_extents_t:create()
	tolua.takeownership(extents)
	local blurred=nil
	local c=txj.c						or default_color		or 0xffffff
	local a=txj.a						or default_alpha		or 1
	local f=txj.f						or default_font			or "mono"
	local fs=txj.fs						or default_font_size	or 12
	local x=txj.x						or 100
	local y=txj.y						or 100
	local txt=txj.txt					or "set txt"
	local face=txj.face					or default_face			or "normal"
	local size=txj.size     			or default_size         or "normal_c"
	--------------------------------------------------------------------
	local hj=txj.hj						or default_hj			or "l"
	--------------------------------------------------------------------
	local shaded=txj.shaded				or default_shaded		or "no"
	local shade_color=txj.shade_color	or default_shade_color	or 0x000000
	local shade_alpha=txj.shade_alpha	or default_shade_alpha	or 1
	--------------------------------------------------------------------
	local underline=txj.underline     	or default_underline    or "no"
	local line_color=txj.line_color    	or   default_line_color or   c
	local line_space=txj.line_space    	or default_line_space   or  5
	local line_width=txj.line_width     or default_line_width   or  1
	--------------------------------------------------------------------
	local number=txj.number  or 8
	local radius=txj.radius or 1.75
	local blurred=txj.blurred or no
	local blurred_color=txj.blurred_color or c
	local blurred_alpha=txj.blurred_alpha or 1
	--------------------------------------------------------------------
	local border=txj.border
	local bc=txj.bc or 0x000000
	local ba=txj.ba or 1
	local bw=txj.bw or 1
	--------------------------------------------------------------------
	cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	----------------------
	if size=="big_c" then
	txt=string.upper(txt)
	elseif size=="small_c" then
	txt=string.lower(txt)
	elseif size=="normal_c" then
	txt=txt
	end
	----------------------
	cairo_set_font_size (cr, fs)
	cairo_text_extents(cr,txt,extents)
	local wx=extents.x_advance -- measure spaces too
	local wd=extents.width
	local hy=extents.height
	local bx=extents.x_bearing
	local by=extents.y_bearing+hy
	local tx=x
	local ty=y
	--set horizontal alignment
	if hj=="l" then
		x=x-bx
	elseif hj=="c" then
		x=x-((wx-bx)/2)-bx
	elseif hj=="r" then
		x=x-wx
	end
	if shaded == "yes" then
		cairo_move_to (cr,(x + 1),(y + 1))
		cairo_set_source_rgba (cr,col(shade_color,shade_alpha))
		cairo_show_text (cr,txt)
		cairo_stroke (cr)
	end -- if
	-------------------------------------------------
	cairo_move_to (cr,x,y)
	cairo_set_source_rgba (cr,col(c,a))
	cairo_show_text (cr,txt)
	cairo_stroke (cr)
	--------------------------------------------------
	if border=="yes" then
    cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	cairo_set_font_size (cr, fs);
	cairo_move_to (cr, x, y);
	cairo_text_path (cr,txt);
	cairo_set_source_rgba (cr,col(c,a));
	cairo_fill_preserve (cr);
	cairo_set_source_rgba (cr,col(bc,ba));
	cairo_set_line_width (cr, bw);
	cairo_stroke (cr);
	end

	-- #################################################################
	-- ## decrease alpha if u want to use a small size #################
	-- ## for example fs=12,blurred="yes",ba=0.1 #######################
	-- #################################################################
	if blurred=="yes" then
	 radi,inum,horiz,verti=radius,number,x,y
	
	 for i=1,inum do
	 deg=360/inum
	 text_arc=((2*math.pi/inum)*i)
	 txs=0+radi*(math.sin(text_arc))
	 tys=0-radi*(math.cos(text_arc))
	 -------------------------------------------------------------------
	 cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	 -------------------------------------------------------------------
	 cairo_set_font_size (cr, fs);
	 cairo_set_source_rgba (cr, col(blurred_color,blurred_alpha));
	 cairo_move_to (cr, txs+horiz, tys+verti);
	 cairo_show_text (cr, txt)
     end
	 
	elseif blurred=="no" then
	 txt=txt
	end
	--------------------------------------------------
		if string.find(underline,"yes") ~= nil then
		line_cap=CAIRO_LINE_CAP_BUTT
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE)
		----------------------------------------------
		startx=x
		endx=startx+wd
		starty=y+line_space
		endy=y+line_space
		-- draw line beyond text ---------------------
		cairo_set_line_width (cr,line_width)
		cairo_set_line_cap  (cr, line_cap)
		cairo_set_source_rgba (cr,col(line_color,a))
		cairo_move_to (cr,x,starty)
		cairo_line_to (cr,x+wd,endy)
		cairo_stroke (cr)
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT) --# reset antialiasing so we don't screw up other code
		elseif string.find(underline,"no") ~= nil then
		txt=txt
		end
	--------------------------------------------------------

end--of function out 

function font_slant(value)
 	fs=nil
 	
 	if value=="normal" then
	fs=CAIRO_FONT_SLANT_NORMAL
    elseif value=="bold" then
	fs=CAIRO_FONT_SLANT_NORMAL
	elseif value=="italic" then
	fs=CAIRO_FONT_SLANT_ITALIC
    elseif value=="bolditalic" then
    fs=CAIRO_FONT_SLANT_ITALIC
	elseif value=="oblique" then 
    fs=CAIRO_FONT_SLANT_OBLIQUE
	end
	    
	return fs
end

function font_weight(value)
	fw=nil
	
 	if string.find(value,"normal") ~= nil then
	fw=CAIRO_FONT_WEIGHT_NORMAL
    elseif value=="bold" then
	fw=CAIRO_FONT_WEIGHT_BOLD
	elseif value=="italic" then
	fw=CAIRO_FONT_WEIGHT_NORMAL
    elseif value =="bolditalic" then
    fw=CAIRO_FONT_WEIGHT_BOLD
	elseif string.find(value,"oblique") ~= nil then 
    fw=CAIRO_FONT_WEIGHT_NORMAL
	end
	    
	return fw
end



-- #####################################################################
-- ## convert 12h-format into 24h-format ###############################
-- #####################################################################

function convert24(tm,suf)
local tmlen=string.len(tm) -- calculate the length of a string
local colon=string.find(tm,":") -- find character within a string
	if colon~=nil then
	tmhr=string.sub(tm,1,colon-1)
	tmmn=string.sub(tm,colon+1,tmlen)
	else
	tmhr=tm
	tmmn=""
	end
if suf=="PM" and tonumber(tmhr)~=12 then
tmhr=tmhr+12
elseif suf=="PM" and tonumber(tmhr)==12  then
tmhr=12
elseif suf=="AM" and tonumber(tmhr)<10 then
tmhr="0"..tmhr
elseif suf=="AM" and tonumber(tmhr)>=10 and tonumber(tmhr)~=12 then
tmhr=tmhr
elseif suf=="AM" and tonumber(tmhr)==12 then
tmhr="00"
end
if colon~=nil then
return tmhr..":"..tmmn
else
return tmhr
end--if colon~=nil
end--of function

-- #####################################################################
-- ## END OF ORIGINAL SCRIPT ###########################################
-- #####################################################################

function m2n(mn)
--[[
function converts the name of the month into numbers
tonumber -> change type of a value (into a number)
]]--
------------------------------------------------------------------------
local m2n_input=nil
local m2n_input=mn.input or 0
local m2n_input=string.lower(m2n_input) -- convert text into lowercase to match the 'table-entries'
local m2n_lang=nil
local m2n_lang=mn.l or "en"
local month_to_num={} -- initalize table (array)
local output=nil
------------------------------------------------------------------------
if m2n_lang=="de" then
 month_to_num={"januar","februar","märz","april","mai","juni","juli","august","september","oktober","november","dezember"}
elseif m2n_lang=="it" then
 month_to_num={"gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre"}
elseif m2n_lang=="en" then
--May
 month_to_num={"january","february","march","april","may","june","juli","august","september","octobre","november","december"}
end
------------------------------------------------------------------------
for i,v in ipairs(month_to_num) do
    if tostring(m2n_input)==tostring(v) then
       if tonumber(i)<=9 then
	   output="0"..tonumber(i)
	   elseif tonumber(i)>=10 then
	   output=tonumber(i)
	   end
	end
end--of loop
return output
end--of function


-- #####################################################################
-- ## display external and local images ################################
-- #####################################################################

function image(im) -- display local images
	local x = nil
	local y = nil
	local w = nil	
	local h = nil
	local file = nil
	
	x =im.x or 0
	y =im.y or 0
	w =im.w or default_image_width -- default width is defined within the template
	h =im.h or default_image_height -- default height is defined within the template

	file = tostring(im.file)
	if file == nil then print("set image file") end 
	local show = imlib_load_image(file)
	if show == nil then return end --# if show == nil then 
	imlib_context_set_image(show)
	local WIDTH = nil
	if tonumber(w) == 0 then 
		WIDTH = imlib_image_get_width() 
	else
		WIDTH = tonumber(w)
	end -- if
	local HEIGHT = nil
	if tonumber(h) == 0 then HEIGHT = imlib_image_get_height() else HEIGHT = tonumber(h) end --# if tonumber(h) == 0 then 
	local scaled = imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), WIDTH, HEIGHT)
	imlib_free_image_and_decache()
	imlib_context_set_image(scaled)
	imlib_render_image_on_drawable(x, y)
	imlib_free_image_and_decache()
	show = nil
	WIDTH = nil
	HEIGHT = nil
	x = nil
	y = nil
	w = nil
	h = nil
	file = nil
	scaled = nil
end --# function

function extern(wb)
--[[
display external images (i.a. webcams)
extern({posx=0,posy=0,imgw=250,imgh=250,imgurl="http://www.gco.org.au/sky.jpg",imghdd="opensky.jpg",imgiv=60})
]]--
	local img_nw=nil
	local img_x=nil
	local img_y=nil
	local s=nil
	local j=nil
	local img_w=nil
	local img_h=nil
	local imgwidth=nil
	local imgheight=nil
	local imgt=nil
	local imgw=nil
	local imgh=nil
	--------------------------------------------------------------------
	img_x=wb.posx or 0 -- horizontal postion
	img_y=wb.posy or 0 -- vertical position
	img_w,imgh=wb.imgw,wb.imgh -- image width + height
	j=wb.j or "l" -- justification
	scaled=wb.scaled or "no" -- scale image or use default value
	scale_size=wb.scale_size or 200 -- set scaled width or use default value
	
	img_nw=wb.imghdd or "external_img.jpg" -- set name of the image
	s=wb.imgurl -- url of the external image (webcam etc.)
	img_file='/home/'..username.."/"..img_nw -- define storage location
	img_intervall=wb.imgiv or 60 -- set intervall
	
	-- grab external image from url and save it to hdd
	local updates = tonumber(conky_parse('${updates}'))
	if (math.mod(updates, img_intervall) == 0) then
		os.execute("wget  -q -O "..img_file..' "'..s..'"')
	end
	-- print error message when no image is defined
	if img_file==nil then print("set image file") end
	--------------------------------------------------------------------
	if scaled=="yes" then
		local show = imlib_load_image(img_file)
		if show == nil then return 	end
		imlib_context_set_image(show) -- display defined image if image file exists
		imgwidth= imlib_image_get_width() -- get image width
		imgheight=imlib_image_get_height() -- get image height
		imgw=scale_size
		imgh=(imgw*imgheight)/imgwidth
		imlib_free_image_and_decache() -- remove from cache
	else
		imgw=img_w
		imgh=img_h
	end
	-- set alignment ---------------------------------------------------
	if j=="l" then -- justify left
	 img_x=img_x
	elseif j=="r" then -- justify right
	 img_x=img_x-imgw
	end
	--------------------------------------------------------------------
	image({x=img_x,y=img_y,w=imgw,h=imgh,file=img_file}) -- load image, function image() must exist
end--of function


-- #####################################################################
-- ## functions to modify conky-output #################################
-- #####################################################################

function os_capture(cmd, raw) -- parse shell in lua
	local f = assert(io.popen(cmd, 'r'))
	local s = assert(f:read('*a'))
	f:close()
	if raw then return s end
	s = string.gsub(s, '^%s+', '')
	s = string.gsub(s, '%s+$', '')
	s = string.gsub(s, '[\n\r]+', ' ')
	return s
end



function parseValue(value,value1,value2,del,ending) -- remove ending and add custom ending
	jn=value:gsub(value1,"") 
	if ending=="no" then mv=chgFormat(jn,ending) else mv=chgFormat(jn,ending)..' '..value2 end
return mv
end


function nounit(var,ending,value)
	if var=="no" then ms=value else ms=value.." "..ending end
	return ms
end


function chgFormat(number,ending) --replace decimal point with ,
point=string.find(number,"%p")
if point~=nil then
n1=string.sub(number,1,point-1)
n2=string.sub(number,point,string.len(number))
n2=string.gsub(n2,"^.",",")

	if string.len(n2)==2 then
	n2=n2..""
	elseif string.len(n2)>3 then
	n2=string.sub(n2,1,3)	
	end
else
n1=number
n2=",0"
end

--put in divisions
n1len=string.len(n1)
divs=math.floor((n1len-1)/3)
if n1len>3 then
	for i=1,divs do
	n=n1len-(i*3)
	bit1=string.sub(n1,1,n)
	bit2=string.sub(n1,n+1)
	n1=bit1.."."..bit2
	end
end
output=n1..n2

return output
end

function chgDel(value,del)

local ausgang=nil
local ersteZahl=nil
local rest=nil
local outputNumber=nil

ausgang=string.gsub(value, "(%d*\.*%d+).*", "%1") -- remove ending
ausgang=tonumber(ausgang)

if not ausgang then ausgang=0; end

 if ((ausgang >= 10000) and (ausgang <= 99999.99)) then ----------------
       ersteZahl=string.sub(ausgang,1,2)
       rest=string.sub(ausgang,3,string.len(ausgang))
       
       if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",",")
	   else
	   outputNumber=ersteZahl..','..string.gsub(tostring(rest),"%,",".")
       end
       
 elseif ((ausgang>=1000) and (ausgang <9999.99)) then ------------------
       ersteZahl=string.sub(ausgang,1,1)
       rest=string.sub(ausgang,2,string.len(ausgang))
       
	   if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",del)
	   elseif del=="." then
	   outputNumber=ersteZahl..','..rest
       end
       
 elseif ausgang<999 then  ----------------------------------------------
	   if del=="," then
       outputNumber=string.gsub(tostring(ausgang),"%.",',')
	   elseif del=="." then
	   outputNumber=ausgang
       end
       
 elseif ausgang >=100000 then ------------------------------------------
	   
       ersteZahl=string.sub(ausgang,1,3)
       rest=string.sub(ausgang,4,string.len(ausgang))
       
	   if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",del)
	   elseif del=="." then
	   outputNumber=ersteZahl..','..rest
       end
       -----------------------------------------------------------------
 end

return outputNumber

end -- of function


function add_decimal(input,sign)  -- add decimal place, i.e. 5,0
if string.find(input,"%a")==nil then -- look for string
        if string.find(input,"%p")==nil then         -- only add decimal place when value is a number
        input=input..sign..'0'
        end
end
return input
end

function parse(value,delimiter,ending)
--[[
modify of conky-output
13.5GIB   chg format  13,5 gb
]]--

	local ms=nil
	value = value:gsub(" ","") --# remove spaces to account for inconsistencies in the inclusion of spaces in the output of different conky objects.
	if value==nil then value=0 end
	
	---- short_units no ------------------------------------------------
	if ((string.find(value, "iB") == nil) and (string.find(value, "B") ~= nil)) then
		ms=parseValue(value,"B",e1,delimiter,ending)
	elseif string.find(value, 'KiB') ~= nil then
		ms=parseValue(value,"KiB",e2,delimiter,ending)
	elseif string.find(value, 'MiB') ~= nil then
		ms=parseValue(value,"MiB",e3,delimiter,ending)
	elseif string.find(value, 'GiB') ~= nil then
		ms=parseValue(value,"GiB",e4,delimiter,ending)
	elseif string.find(value, "TiB") ~= nil then
		ms=parseValue(value,"TiB",e5,delimiter,ending)
	---- short_units yes -----------------------------------------------
	elseif ((string.find(value, "iB") == nil) and (string.find(value, "B") ~= nil)) then
		ms=parseValue(value,"B",e1,delimiter,ending)
	elseif string.find(value, "K") ~= nil then
		ms=parseValue(value,"K",e2,delimiter,ending)
	elseif string.find(value, "M") ~= nil then
		ms=parseValue(value,"M",e3,delimiter,ending)
	elseif string.find(value, "G") ~= nil then
		ms=parseValue(value,"G",e4,delimiter,ending)
	elseif string.find(value, "T") ~= nil then
		ms=parseValue(value,"T",e5,delimiter,ending)
	else
		ms=value:gsub(" ","") -- remove space
	end

	return ms
end -- of function


function system(cd)
--[[
variable -> argument for example fs_free
device --> system-device for example wlan0
del --> delimiter of number
tf --> format of shown time for example 01:15 uhr or 1:15 pm
se --> shown ending for example 1.000 mb or 1.000
dt --> show current date

you can call the function like this (example):
system({variable="totaldown",device="wlan0",del=',',se="no"})
]]--

local t=nil

local variable=cd.variable
local device=cd.device or ''
local del=cd.del or '.'
local tf=cd.tf or '24'
local se=cd.se or "yes"
local txt=cd.txt or "yes"
local dt=cd.dt or "no"

rawdata=conky_parse("${"..variable..' '..device.."}")
adv=parse(rawdata,del,se)

	if string.find(variable,"cpu") ~= nil then
		ms=nounit(se,e6,rawdata)
	elseif string.find(variable,"uptime") ~= nil or string.find(variable,"user_number") ~= nil then
		ms=rawdata
	elseif ((string.find(variable, "perc") ~= nil) or (string.find(variable, "percent") ~= nil)) then
	--------------------------------------------------------------------	
		if string.find(variable, "fs") ~= nil then
		ms=conky_parse("${if_mounted "..device.."}"..nounit(se,e6,rawdata).."${else}"..t3.."${endif}")
		else ms=nounit(se,e6,rawdata) end
	--------------------------------------------------------------------
	elseif ((string.find(variable,"freq") ~= nil) and (string.find(variable,"_g") == nil)) then
		jn=chgDel(adv,del)
		ms=nounit(se,e7,jn)
	elseif ((string.find(variable,"freq") ~= nil) and (string.find(variable,"_g") ~= nil)) then
		jn=chgDel(adv,del)
		ms=nounit(se,e8,add_decimal(jn,del))
	elseif string.find(variable,"loadavg") ~= nil then
		ms=rawdata
	--------------------------------------------------------------------
	elseif string.find(variable,"wireless_bitrate") ~= nil then
		t=rawdata:gsub("Mb/s","")
		t=chgDel(t,del)
		t=add_decimal(t,del)
		t=t:gsub(" ","") -- remove spaces
		ms=conky_parse("${if_up "..device.."}"..nounit(se,e9,t).."${else}"..t4.."${endif}")
	elseif string.find(variable,"wireless_essid") ~= nil or string.find(variable,"wireless_mode") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..rawdata.."${else}"..t4.."${endif}")
	elseif string.find(variable,"wireless_link_qual") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..nounit(se,e6,adv).."${else}"..t4.."${endif}")
	elseif string.find(variable,"upspeedf") ~= nil or string.find(variable,"downspeedf") ~= nil then
		jn=chgDel(adv,del) -- chg format
		ms=conky_parse("${if_up "..device.."}"..nounit(se,e10,add_decimal(jn,del)).."${else}"..t4.."${endif}")
	elseif string.find(variable,"battery") ~= nil then
		ms=rawdata
	--------------------------------------------------------------------
	elseif string.find(variable,"up") == nil and string.find(variable,"time") ~= nil then
		

if dt=="yes" then
ms=nounit(se,"",adv)
ms=ms:gsub(" ","")
else

if tf == "24" then ms=nounit(se,e11,adv) elseif tf == "12" then ms=convert12(rawdata,tf) end 

end

--[[
%B name of the month
%m month number, for example 05
%y year short number, for example 13
%Y year long number, for example 2013
%d day number
]]--

	else
	--------------------------------------------------------------------
		if string.find(device,"wlan") ~= nil or string.find(device,"eth") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..adv.."${else}"..t4.."${endif}")
		elseif string.find(device,"media") ~= nil then
		  --------------------------------------------------------------
          if txt=="no" and string.find(variable,"free") ~= nil then
           ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..t3.."${endif}")
          elseif txt=="yes" and string.find(variable,"free") ~= nil then
           ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t1.."${else}"..t3.."${endif}")

		  elseif txt=="no" and string.find(variable,"used") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..t3.."${endif}")
		  elseif txt=="yes" and string.find(variable,"used") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t2.."${else}"..t3.."${endif}")
		   
		  elseif txt=="no" and string.find(variable,"size") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..t3.."${endif}")
		  elseif txt=="yes" and string.find(variable,"size") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t5.."${else}"..t3.."${endif}")
		   
		  end
		  --------------------------------------------------------------
		else ms=adv  end 
	--------------------------------------------------------------------
	end

	return ms
end -- of function

-- convert 24h-format into 12h-format, for example 16:00 -> 4:00 pm
function convert12(value,format) 

local stunden=nil
local minuten=nil
local zeit=nil
local sekunden=nil

local stunden=string.sub(value,1,2) 	-- hours
local stunden=tonumber(stunden) 		-- convert hours into numbers
local minuten=string.sub(value,4,5)	 	-- minutes
local sekunden=string.sub(value,7,8) 	-- seconds

-- still calculate if string doesn't exists
if not sekunden then sekunden=''; end

if stunden > 12 and stunden < 24 then
	if sekunden ~= '' then
	zeit=(stunden-12)..':'..minuten..':'..sekunden..' pm'
	elseif sekunden == '' then
	zeit=(stunden-12)..':'..minuten..' pm'
	end
elseif stunden < 12 then
	if sekunden ~= '' then
	zeit=stunden..':'..minuten..':'..sekunden..' am'
	elseif sekunden == '' then
	zeit=stunden..':'..minuten..' am'
	end
elseif stunden == 12 then
	if sekunden ~= '' then
	zeit=stunden..':'..minuten..':'..sekunden..' pm'
	elseif sekunden == '' then
	zeit=stunden..':'..minuten..' pm'
	end
elseif stunden == 24 or stunden == 0 then
	if sekunden ~= '' then
	zeit=(stunden-12)..':'..minuten..':'..sekunden..' am'
	elseif sekunden == '' then
	zeit=(stunden-12)..':'..minuten..' am'
	end
end

return zeit

end


function dropZero(wert) -- drop leading charcacter

local ausgabe=nil
local erstezahl=tonumber(string.sub(wert,1,1))

 if erstezahl == 0 then
 ausgabe=string.sub(wert,2,5)
 else
 ausgabe=string.sub(wert,1,5)
 end -- of if

return ausgabe

end -- of function


function draw_bar(db) -- draw simple bar
------------------------------------------------------------------------
local var=nil
local dev=nil
local width=nil
local height=nil
local across=nil
local down=nil
local bgc=nil
local bga=nil
local inc=nil
local ina=nil
local lc=nil
local la=nil
local lw=nil
local rotate=nil
local justify=nil
------------------------------------------------------------------------
var=db.var
m=db.max or 100
dev=db.dev or ""
width,height=db.w,db.h
across,down=db.x,db.y
bgc,inc,lc=db.bgc,db.indc,db.lc
------------------------------------------------------------------------
bga=db.bga or 1
ina=db.inda or 1
la=db.la or 1
------------------------------------------------------------------------
lw=db.lw
rotate=db.r or 0
justify=db.j or "l"
------------------------------------------------------------------------
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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
------------------------------------------------------------------------
if updates>5 then -- starts the display

--indicator calculation
if not dev then dev=''; end

conum=conky_parse("${"..var..' '..dev.."}")
conum=tonumber(conum)

local inum=(((width-lw)/100)*(conum or 0))
local x =  100 * inum / m

-- justify bar
if justify=="r" then across=across-width elseif justify=="l" then across=across end

-- background bar ------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_source_rgba (cr, col(bgc, bga));
cairo_rectangle (cr, 0, 0, (width-lw), (height-lw))
cairo_fill (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
--indicator bar --------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_source_rgba (cr, col(inc,ina));
cairo_rectangle (cr, 0, 0, x, (height-lw))
cairo_fill (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
--boundary line --------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_line_width (cr, lw);
cairo_set_source_rgba (cr, col(lc,la));
cairo_rectangle (cr, -lw/2, -lw/2, width, height)
cairo_stroke (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
	end
end

-- ################################################
-- ## umwandeln von zahlen in wörter ########################
-- ################################################

function n2w(number)
--by mrpeachy 11-4-2012
local n1_tab={}
local n2_tab={}
number=tonumber(number)
local n_len=string.len(number)
if number<0 then
number=tonumber(string.sub(number,2,n_len))
minus="minus "
else
number=number
minus=""
end
if number>99 then
h=tonumber(string.sub(number,1,1))
tu=tonumber(string.sub(number,2,3))
t=tonumber(string.sub(number,2,2))
u=tonumber(string.sub(number,3,3))
elseif number<100 then
tu=number
t=tonumber(string.sub(number,1,1))
u=tonumber(string.sub(number,2,2))
end
n1_tab={"eins","zwei","drei","vier","fünf","sechs","sieben","acht","neun","zehn","elf","zwölf","dreizehn","vierzehn","fünfzehn","sechzehn","siebzehn","achtzehn","neunzehn",}
n2_tab={"zehn","zwanzig","dreißig","vierzig","fünfzig","sechzig","siebzig","achtzig","neunzig"}
if number>0 then n0="" else n0="null" end
if tu<20 and tu~=10 and tu~=0 then 
	ausgabe=n1_tab[tu]
elseif tu==10 then
	ausgabe="zehn"
elseif tu==0 then
	ausgabe="null"
elseif tu>19 then
	if u>0 then 
	joinu=" " 
	u=n1_tab[u]
	else 
	joinu=""
	u=""
	end
	g=string.sub(number,2,2)
	ausgabe=international(tu,g,n2_tab[t])
--	out=n2_tab[t]..joinu..u -- original
end
if number>99 and number~=100 then
	h=n1_tab[h]
	return minus..h.." hundred and "..ausgabe
elseif number==100 then
	return "einhundert"
elseif number<100 then
	return minus..ausgabe
end
end--function

function international(lang,geschnitten,wort)
local nummer=nil
local kurzezahl=nil

local anzahl=tonumber(lang)
local kurzezahl=tonumber(geschnitten)

if kurzezahl==1 or anzahl==1 then

 if string.len(anzahl)>1  then
 nummer='einund'..n2_tab[t]     -- gives me for example 21, 31 etc
 elseif string.len(anzahl)==1 then
 nummer='eins'			        -- gives me the number 1
 end

elseif kurzezahl~=1 or anzahl ~=1 then

   if anzahl==0 then
   nummer=wort                                     -- should give me the word 'null' (zero)
   elseif tonumber(string.sub(anzahl,1,1)) and tonumber(string.sub(anzahl,2,2))==0 then   --
   nummer=wort                                     -- gives me numbers like 10,20,30 etc.
   else 
    nummer=n2w(kurzezahl)..'und'..wort         --  gives me such numbers like 22,23,24 etc.
    end

end

return nummer

end -- der fun ktion

-- #####################################################################
-- ## end of functions to modify conky-output ##########################
-- #####################################################################


-- #####################################################################
-- ## gimmicks #########################################################
-- #####################################################################

function get_image() -- grab url of the 'image of the day' by the nasa 
	local uri='http://www.nasa.gov/rss/image_of_the_day.rss' -- address of rss-file 
	local f = assert(io.popen('curl -s '..uri, 'r')) -- get content of the rss-file
	local s = assert(f:read('*a'))
	f:close()
	s, f = string.gsub(s, ".*image\/jpeg.*(http://.*\.jpg).*", "%1")
	return s
end


function potw_uri() --  grab url of the 'picture of the week' by hubble 
	local uri = 'http://feeds.feedburner.com/hubble_potw?format=xml'
	local f = assert(io.popen('curl -s '..uri, 'r'))
	local s = assert(f:read('*a'))
	f:close()
	local b = nil
	local e = nil
	b,e,s = string.find(s,'(http://www%.spacetelescope%.org/static/archives/images/news/potw%d-.%.jpg)')
	return(s)
end

--END OF SCRIPT

Offline

#5467 2013-05-30 16:20:54

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

easysid wrote:

Also remove this line from for loop

settings_t[i].fg_color[2] = alpha --substitute the alpha of fg_color

It should work then.

That's the line I didn't see.  big_smile
Thanks


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#5468 2013-05-30 16:57:33

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: Conky v1.9 Thread

easysid wrote:

Something I am working on.
http://i.imgur.com/UcjqjB0.png

The ones on bottom row use color filling to indicate the variable. Even in the top ones, there is an issue of text being larger than the petals. Slight adjustments are needed but those are difficult to code. So, I'll probably hand hack the placement of text :8

What's the problem.
If you have coordinates of the center of the petal then you halve width of the text (available from the text extent) and extract it from the coordinates of the center to find starting point for the text.
It can be done every loop to ensure to have right values for ever changing text (it could jump if text is changing too often).


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

#5469 2013-05-30 17:07:36

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

Re: Conky v1.9 Thread

dk75 wrote:

What's the problem.
If you have coordinates of the center of the petal then you halve width of the text (available from the text extent) and extract it from the coordinates of the center to find starting point for the text.
It can be done every loop to ensure to have right values for ever changing text (it could jump if text is changing too often).

Didn't know about text extents. Reading them right now. That ought to do it. Thanks a lot smile

Offline

#5470 2013-05-30 17:43:49

lionhead
#! Junkie
From: Dagobah / Germany
Registered: 2011-01-22
Posts: 459

Re: Conky v1.9 Thread

lionhead wrote:

hello

i have a little problem. the script only shows values when the the drive is mounted.

because the harddrive is always mounted it should show the value (for example 50%) and NOT the word.

here the screenshot: http://i.imgbox.com/abbLB3Jx.jpg

this is the code:

-- weather v9000 by mrpeachy 01/10/12; released: Feb 29, 2012
-- official update by mrpeachy
-- additional features by lionhead, arclance and dk75
-- optimize lua: http://lua-users.org/wiki/OptimizedStrRep
-- last update 29.05.2013

require 'cairo'
require 'imlib2'
local username = os.getenv("USERNAME")

--you can enter your username here in case of errors, 
--enter username in quotes like this username = "yourname"
local username = "alexander"

-- you need to translate this text
local t1="frei" -- when u use fs_free or fs_free_perc
local t2="belegt" -- when u use fs_size
local t5="gesamt" -- when u use fs_used or fs_used_perc

local t3="not mounted" -- display text when hardrive/usb-stick is unmounted
local t4="n/a" -- display text when internet connection is not avaiable

-- customize ending
local e1="byte"
local e2="kb"
local e3="mb"
local e4="gb"
local e5="tb"
local e6="%"
local e7="mhz"
local e8="ghz"
local e9="mb/s"
local e10="kb/s"
local e11="uhr"

package.path = '/home/'..username..'/.v9000_config.lua'
require '.v9000_config'

-- #####################################################################
-- ## end of translation ###############################################
-- #####################################################################

start=1
--INITIALIZE SETTINGS-- need only be run once
settings_table=weather_settings()
--##################################
--######## main function ########### 
function conky_weather()--##########
-- function to convert color into hex-code
function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function

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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
--###UNCOMMENT THE BELOW LINE TO ENABLE CPU DELAY##########################################################
--if updates>5 then--###### YOU WILL ALSO HAVE TO UNCOMMENT THE MATCHING end ON LINE 923 ####################
--#########################################################################################################
local testing=0--this setting is for script testing, if not in testing set to 0
--#########################################################################################################
--############start of timed section#######################################################################
--#########################################################################################################
local timer=(updates %tonumber(settings_table[1]))
if timer==0 or start==1 then--######
start=nil--#######################################
local web=settings_table[2]
local alert_check=settings_table[13]
print ("gathering data with curl")
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
allweatherdata=f:read("*a")
f:close()
allweatherdata=string.gsub(allweatherdata,"[\n\r]","")
testall=string.find(allweatherdata,">10 Day Forecast&nbsp")
--CHECK FOR WEATHER ALERTS
if testall~=nil and alert_check==1 then
local alert=string.find(allweatherdata,"Severe Weather Alert!")
	if alert~=nil then
	print ("getting weather alerts")
	--get alert web
	local a,b,alertchunk=string.find(allweatherdata,">Local Information</div>(.*)>Severe Weather Alert!<")
	local a,b,alertsite=string.find(alertchunk,"><a href=%p(.*)%p><img src=")
	local f=io.popen("curl --max-time 60 'http://www.intellicast.com"..alertsite.."' | sed 's/%//g'")
	alertdata=f:read("*a")
	f:close()
	alertdata=string.gsub(alertdata,"[\n\r]","")
	alerttest=string.find(alertdata,"%a")
	else
	print ("you have no weather alerts")
	alerttest=0
	end--if alert~=nil
else
print ("not checking for alerts")
alerttest=1
end--if testall and alert check
processall=1
end--of timed data gathering section
--in case curl craps up it should retry until it works
if testall==nil or  alerttest==nil then
print ("curl attempt timed out, trying again")
local web=settings_table[2]
local alert_check=settings_table[13]
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
allweatherdata=f:read("*a")
f:close()
allweatherdata=string.gsub(allweatherdata,"[\n\r]","")
testall=string.find(allweatherdata,">10 Day Forecast&nbsp")
--CHECK FOR WEATHER ALERTS
if testall~=nil and alert_check==1 then
local alert=string.find(allweatherdata,"Severe Weather Alert!")
	if alert~=nil then
	print ("getting weather alerts")
	--get alert web
	local a,b,alertchunk=string.find(allweatherdata,">Local Information</div>(.*)>Severe Weather Alert!<")
	local a,b,alertsite=string.find(alertchunk,"><a href=%p(.*)%p><img src=")
	local f=io.popen("curl --max-time 60 'http://www.intellicast.com"..alertsite.."' | sed 's/%//g'")
	alertdata=f:read("*a")
	f:close()
	alertdata=string.gsub(alertdata,"[\n\r]","")
	alerttest=string.find(alertdata,"%a")
	else
	print ("you have no weather alerts")
	alerttest=0
	end--if alert~=nil
else
print ("not checking for alerts")
alerttest=1
end--if testall and alert_check
processall=1
end--if testall==nil
--end or curl reruns
--START PROCESSING ###########################################################################
if testall~=nil and alerttest~=nil and processall==1 then
local weathericons=settings_table[3]
local con_short=settings_table[4]
local visibility_unit=settings_table[6]
local wind_mph_unit=settings_table[7]
local wind_km_unit=settings_table[8]
local wind_kts_unit=settings_table[9]
local ceiling_unit=settings_table[10]
local wind_degrees_unit=settings_table[11]
local translate=settings_table[12]
local alert_check=settings_table[13]
--LOAD TRANSLATE TABLES IF TRANSLATE SETTING = 1
	if translate==1 then
	monthshort=settings_table[21]
	monthnames=settings_table[20]
	dayhort=settings_table[19]
	daynames=settings_table[18]
	neswtext=settings_table[14]
	tsuffix=settings_table[15]
	uvindextext=settings_table[16]
	moonphases=settings_table[17]
	additional=settings_table[22]
	else--neswtext,tsuffix,uvindextext,moonphases,daynames,dayshort,monthnames,monthshort

	dayshort={Monday="Mon",Tuesday="Tue",Wednesday="Wed",Thursday="Thu",Friday="Fri",Saturday="Sat",Sunday="Sun"}
	monthshort={January="Jan",February="Feb",March="Mar",April="Apr",May="May",June="Jun",July="Jul",August="Aug",September="Sep",October="Oct",November="Nov",December="Dec"}
	end--end if translate =1
--process data tables
--intellicast to conky weather icon conversion
wimage={
wx_65="32",  -- Clear
wx_66="30",  -- Partly Cloudy
wx_67="26",  -- Cloudy
wx_68="32",  -- Clear
wx_69="28",  -- Mostly Cloudy
wx_70="20",  -- Fog
wx_71="32",  -- Clear
wx_72="21",  -- Haze
wx_73="36",  -- Hot
wx_74="14",  -- Light Snow Showers
wx_75="28",  -- Mostly Cloudy
wx_76="18",  -- Sleet
wx_77="14",  -- Light Snow Showers
wx_78="23",  -- Blustery
wx_79="05",  -- Mixed Rain and Snow
wx_80="15",  -- Drifting Snow
wx_81="15",  -- Drifting Snow
wx_82="11",  -- Light Rain
wx_83="16",  -- Snow
wx_84="00",  -- Tornado
wx_85="32",  -- Clear
wx_86="25",  -- N/A
wx_87="09",  -- Drizzle
wx_88="05",  -- Mixed Rain and Snow
wx_89="18",  -- Sleet
wx_90="18",  -- Sleet
wx_91="39",  -- Scattered Showers
wx_92="39",  -- Scattered Showers
wx_93="39",  -- Scattered Showers
wx_94="39",  -- Scattered Showers
wx_95="37",  -- Isolated Thunderstorms
wx_96="37",  -- Isolated Thunderstorms
wx_97="31",  -- Clear
wx_98="29",  -- Partly Cloudy
wx_99="27",  -- Mostly Cloudy
wx_100="47",  -- Isolated Thunderstorms
wx_101="47",  -- Isolated Thunderstorms
wx_102="33",  -- Fair
wx_103="26",  -- Cloudy
wx_104="20",  -- Fog
wx_105="45",  -- Scattered Showers
wx_106="45",  -- Scattered Showers
wx_107="11",  -- Light Rain
wx_108="46",  -- Snow Showers
wx_109="46",  -- Snow Showers
wx_110="06",  -- Mixed Rain and Sleet
wx_111="18",  -- Sleet
wx_112="06",  -- Mixed Rain and Sleet
wx_113="46",  -- Snow Showers
wx_114="46",  -- Snow Showers
wx_115="31",  -- Clear
wx_116="47",  -- Isolated Thunderstorms
}--end w image table
--convert intellicast icons to weather font
wfont={
wx_65="a",
wx_66="c",
wx_67="f",
wx_68="a",
wx_69="d",
wx_70="0",
wx_71="a",
wx_72="9",
wx_73="5",
wx_74="p",
wx_75="d",
wx_76="w",
wx_77="p",
wx_78="6",
wx_79="x",
wx_80="8",
wx_81="8",
wx_82="h",
wx_83="q",
wx_84="m",
wx_85="a",
wx_86="-",
wx_87="h",
wx_88="x",
wx_89="w",
wx_90="w",
wx_91="g",
wx_92="g",
wx_93="g",
wx_94="g",
wx_95="k",
wx_96="k",
wx_97="A",
wx_98="C",
wx_99="D",
wx_100="K",
wx_101="K",
wx_102="B",
wx_103="f",
wx_104="0",
wx_105="G",
wx_106="G",
wx_107="h",
wx_108="O",
wx_109="O",
wx_110="x",
wx_111="w",
wx_112="x",
wx_113="O",
wx_114="O",
wx_115="A",
wx_116="K",
}--end w font table
--conversion day and month tables
moonfontt={
["New"]="@",
["Full"]="=",
["First Quarter"]="T",
["Last Quarter"]="G",
["Waning Gibbous"]="D",
["Waning Crescent"]="J",
["Waxing Crescent"]="Q",
["Waxing Gibbous"]="W",
}--end of moon font table
moonicont={
["New"]=weathericons.."moon_new.png",
["Full"]=weathericons.."moon_full.png",
["First Quarter"]=weathericons.."moon_first_quarter.png",
["Last Quarter"]=weathericons.."moon_last_quarter.png",
["Waning Gibbous"]=weathericons.."moon_waning_gibbous.png",
["Waning Crescent"]=weathericons.."moon_waning_crescent.png",
["Waxing Crescent"]=weathericons.."moon_waxing_crescent.png",
["Waxing Gibbous"]=weathericons.."moon_waxing_gibbous.png",
}--end of moon icon table
windfontt={
S="9",
SSW=":",
SW=";",
WSW="<",
W="=",
WNW=">",
NW="?",
NNW="@",
N="1",
NNE="2",
NE="3",
ENE="4",
E="5",
ESE="6",
SE="7",
SSE="8"
}--end of wind direction font table
--setup tables for forecast weather
forecast_day={}
forecast_day_caps={}
forecast_day_lc={}
forecast_day_short={}
forecast_day_short_caps={}
forecast_day_short_lc={}
forecast_month={}
forecast_month_caps={}
forecast_month_lc={}
forecast_month_short={}
forecast_month_short_caps={}
forecast_month_short_lc={}
forecast_date={}
weather_icon={}
weather_font={}
high_temp={}
low_temp={}
conditions={}
conditions_caps={}
conditions_lc={}
conditions_short={}
conditions_short_caps={}
conditions_short_lc={}
sun_rise={}
sun_rise_lc={}
sun_rise_time={}
sun_rise_24={}
moon_rise={}
moon_rise_lc={}
moon_rise_time={}
moon_rise_24={}
moon_rise_ampm={}
moon_rise_ampm_lc={}
sun_set={}
sun_set_lc={}
sun_set_time={}
sun_set_24={}
moon_set={}
moon_set_lc={}
moon_set_time={}
moon_set_24={}
moon_set_ampm={}
moon_set_ampm_lc={}
humidity={}
precipitation={}
snow={}
cloud_cover={}
moon_phase={}
moon_phase_caps={}
moon_phase_lc={}
moon_font={}
moon_icon={}
wind_mph={}
wind_km={}
wind_kts={}
wind_font={}
wind_icon={}
wind_deg={}
wind_nesw={}
uv_index_num={}
uv_index_txt={}
uv_index_txt_caps={}
uv_index_txt_lc={}
--get forecast chunk --------------------------------------------------------
local a,b,allweather=string.find(allweatherdata,">10 Day Forecast&nbsp(.*)>More from Intellicast</div>")
--extract information into tables
local start=0
local f=1
while f~=nil do
--match forecast day name and date
local s,f,t=string.find(allweather,"<td colspan=\"2\"><strong>([%a,%s%d]*)</strong></td>",start)
	if t~=nil then
	--split name from month and date
	local a,b,day=string.find(t,"(%a*),%s")
	local a,b,month=string.find(t,",%s(%a*)%s")
	local a,b,date=string.find(t,"(%d*)$")
	--set day names, regular, caps, lowercase and short
	table.insert(forecast_day_short,dayshort[day])
	table.insert(forecast_day_short_caps,string.upper(dayshort[day]))
	table.insert(forecast_day_short_lc,string.lower(dayshort[day]))
		if translate==1 then
		day=daynames[day]
		else
		day=day
		end
	table.insert(forecast_day,day)
	table.insert(forecast_day_caps,string.upper(day))
	table.insert(forecast_day_lc,string.lower(day))
	--set month types
	table.insert(forecast_month_short,monthshort[month])
	table.insert(forecast_month_short_caps,string.upper(monthshort[month]))
	table.insert(forecast_month_short_lc,string.lower(monthshort[month]))
		if translate==1 then
		month=monthnames[month]
		else
		month=month
		end
	table.insert(forecast_month,month)
	table.insert(forecast_month_caps,string.upper(month))
	table.insert(forecast_month_lc,string.lower(month))
	--set date
	table.insert(forecast_date,date)
	end--if t~= nil
--intellicast weather icon match
local s,f,t=string.find(allweather,"40_white/(wx_[%d]*).png\"",start)
--convert to conkyweather icon
	if t~=nil then
	table.insert(weather_icon,weathericons..wimage[t]..".png")
	--convert to weather font
	table.insert(weather_font,wfont[t])
	end
--match conditions
local s,f,t=string.find(allweather," /><br />([%a%s%p]*)</td>",start)
	if t~=nil then
	table.insert(conditions,t)
	table.insert(conditions_caps,string.upper(t))
	table.insert(conditions_lc,string.lower(t))
	--set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	----------------------------------------------------
	table.insert(conditions_short,cons)
	table.insert(conditions_short_caps,string.upper(cons))
	table.insert(conditions_short_lc,string.lower(cons))
	end
--match high temp
local s,f,t=string.find(allweather,"\"Hi\">([%p%d]*)&deg",start)
table.insert(high_temp,t)
--match low temp
local s,f,t=string.find(allweather,"\"Lo\">([%p%d]*)&deg",start)
table.insert(low_temp,t)
--match sun rise times
local s,f,t=string.find(allweather,"Rise:</strong> (%d*:%d*%s%u%u)</td>",start)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(sun_rise_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(sun_rise,tm.." "..suf)
	table.insert(sun_rise_lc,string.lower(tm.." "..suf))
	table.insert(sun_rise_time,tm)
	end
--match sun set times
local s,f,t=string.find(allweather,"Set:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then	
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(sun_set_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(sun_set,tm.." "..suf)
	table.insert(sun_set_lc,string.lower(tm.." "..suf))
	table.insert(sun_set_time,tm)
	end
--moon rise
local s,f,t=string.find(allweather,"Rise:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(moon_rise_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(moon_rise,tm.." "..suf)
	table.insert(moon_rise_lc,string.lower(tm.." "..suf))
	table.insert(moon_rise_time,tm)
	table.insert(moon_rise_ampm,suf)
	table.insert(moon_rise_ampm_lc,string.lower(suf))
	end
--moon set
local s,f,t=string.find(allweather,"Set:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(moon_set_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(moon_set,tm.." "..suf)
	table.insert(moon_set_lc,string.lower(tm.." "..suf))
	table.insert(moon_set_time,tm)
	table.insert(moon_set_ampm,suf)
	table.insert(moon_set_ampm_lc,string.lower(suf))
	end
--match uv index
local s,f,tuv=string.find(allweather,"UV Index:</strong>%s*(%d*%s*%([%a%s]*%))%s*<br />",start)
if tuv~=nil then
	--get just number
	local a,b,unm=string.find(tuv,"(%d*)%s*%([%a%s]*%)")
	--get just text
	local a,b,utx=string.find(tuv,"%d*%s*%(([%a%s]*)%)")
	table.insert(uv_index_num,unm)
		if translate==1 then
		utx=uvindextext[utx]
		else
		utx=utx
		end
	table.insert(uv_index_txt,utx)
	table.insert(uv_index_txt_caps,string.upper(utx))
	table.insert(uv_index_txt_lc,string.lower(utx))
	end
--match humidity
local s,f,t=string.find(allweather,"Humidity:</strong> (%d*)<br />",start)
table.insert(humidity,t)
--match ppt
local s,f,t=string.find(allweather,"Precipitation:</strong> (%d*)<br />",start)
table.insert(precipitation,t)
--match snow %
local s,f,t=string.find(allweather,"Snow Probability:</strong>%s*(%d*)<br />",start)
table.insert(snow,t)
--match cloud coverage
local s,f,t=string.find(allweather,"Cloud Coverage:</strong> (%d*)<br />",start)
table.insert(cloud_cover,t)
--match moon phase
local s,f,t=string.find(allweather,"Moon Phase:</strong> ([%a%s]*) <br />",start)
--set moon phase text
	if t~= nil then
	--set moon phase font and icon
	table.insert(moon_font,moonfontt[t])
	table.insert(moon_icon,moonicont[t])
		if translate==1 then
		t=moonphases[t]
		else
		t=t
		end
	table.insert(moon_phase,t)
	table.insert(moon_phase_caps,string.upper(t))
	table.insert(moon_phase_lc,string.lower(t))
	end
--match wind speeds
local s,f,tmph=string.find(allweather,"Wind Speed:</strong> (%d*)Mph",start)
local tmph=tonumber(tmph)
table.insert(wind_mph,tmph)
local s,f,t=string.find(allweather,"Mph%s*%((%d*)Km,",start)
table.insert(wind_km,t)
local s,f,t=string.find(allweather,"Km,%s*(%d*)Kts%)",start)
table.insert(wind_kts,t)
--match wind direction
local s,f,twd=string.find(allweather,"Wind Direction:</strong> ([%d&;%s%(%a%)]*)%s*</div>",start)
	if twd~=nil then
	local a,b,tdeg=string.find(twd,"(%d*)&deg;")
	table.insert(wind_deg,tdeg)
	--match wind font and nesw   
	local a,b,tnesw=string.find(twd,"%((%a*)%)")
	table.insert(wind_font,windfontt[tnesw])
		if tmph>0 and tmph<19 then
		table.insert(wind_icon,weathericons.."green_"..string.lower(tnesw)..".png")
		elseif tmph>18 and tmph<38 then
		table.insert(wind_icon,weathericons.."yellow_"..string.lower(tnesw)..".png")
		elseif tmph>37 and tmph<64 then
		table.insert(wind_icon,weathericons.."orange_"..string.lower(tnesw)..".png")
		elseif tmph>63 then
		table.insert(wind_icon,weathericons.."green_"..string.lower(tnesw)..".png")
		elseif tmph==0 then
		table.insert(wind_icon,weathericons.."no_wind.png")
		end
		if translate==1 then
		tnesw=neswtext[tnesw]
		else
		tnesw=tnesw
		end
	table.insert(wind_nesw,tnesw)
	end
if f==nil then break end
start=f
end--while
--get location
local a,b,wl=string.find(allweatherdata,"<title>%s*Intellicast%s%p%s(.*)</title>")
weather_location=string.gsub(wl," Extended Forecast in",",")
--format now weather
--extract current data
--get now weather chunk
local a,b,nowweather=string.find(allweatherdata,">Current Conditions&nbsp(.*)>View Detailed Observations for the last<br />")
now={}
monthlong={Jan="January",Feb="February",Mar="March",Apr="April",May="May",Jun="June",Jul="July",Aug="August",Sep="September",Oct="October",Nov="November",Dec="December"}
local s,f,tnow=string.find(nowweather,"<div style=\"float:right;color:#666;\">  As of ([%d%p%a%s]*) %(Local Time%)")
local s,f,t=string.find(tnow,"(%d*%p%d*%s%a*) on")
--get time only
local a,b,ntm=string.find(t,"(%d*%p%d*)")
--get suffix only
local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
now["time_24"]=convert24(ntm,suf)
if translate==1 then
suf=tsuffix[suf]
else
suf=suf
end
now["time"]=ntm.." "..suf
now["time_lc"]=string.lower(ntm.." "..suf)
now["time_num"]=ntm
now["time_ampm"]=suf
now["time_ampm_lc"]=string.lower(suf)
--get day
local s,f,t=string.find(tnow,"on (%a*)%s%d*")
if translate==1 then
day=daynames[t]
else
day=t
end
now["day"]=day
now["day_caps"]=string.upper(day)
now["day_lc"]=string.lower(day)
--short day names
local ds=dayshort[t]
now["day_short"]=ds
now["day_short_caps"]=string.upper(ds)
now["day_short_lc"]=string.lower(ds)
--get date
local s,f,t=string.find(tnow,"%s(%d%d)%s")
now["date"]=t
--get months
local s,f,t=string.find(tnow,"%d%d%s(%a*)%s%d")
if translate==1 then
mnth=monthlong[t]
now["month_short"]=monthshort[mnth]
now["month_short_caps"]=string.upper(monthshort[mnth])
now["month_short_lc"]=string.lower(monthshort[mnth])
mnth=monthnames[mnth]
else
now["month_short"]=t
now["month_short_caps"]=string.upper(t)
now["month_short_lc"]=string.lower(t)
mnth=monthlong[t]
end
now["month"]=mnth
now["month_caps"]=string.upper(mnth)
now["month_lc"]=string.lower(mnth)
local s,f,t=string.find(tnow,"%a%a%a%s(%d%d%d%d)")
now["year"]=t
local s,f,t=string.find(nowweather,"40_white/(wx_[%d]*)%ppng%p%stitle=%p")
now["weather_icon"]=weathericons..wimage[t]..".png"
now["weather_font"]=wfont[t]
local s,f,t=string.find(nowweather,"class=%pIcon%p /> ([%a%s%p]*)%s*%s*</td>%s*<td class=%pEmpty%p>&nbsp;")
local t=t:gsub("^%s*(.-)%s*$", "%1")
now["conditions"]=t
now["conditions_caps"]=string.upper(t)
now["conditions_lc"]=string.lower(t)
--set short versions------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["conditions_short"]=cons
	now["conditions_short_caps"]=string.upper(cons)
	now["conditions_short_lc"]=string.lower(cons)
--------------------------------------------
local s,f,t=string.find(nowweather,"Temperature\">([%p%d]*)&deg")
now["temp"]=t
local s,f,t=string.find(nowweather,">Feels Like: ([%p%d]*)&deg;</a>")
now["feels_like"]=t
local s,f,t=string.find(nowweather,">Wind Chill: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["wind_chill"]=t
local s,f,t=string.find(nowweather,">Ceiling: </a></td>%s*<td>([%a%d]*)</td>")
if t~="Unl" then
local s,f,t=string.find(t,"([%d%p]*)")
tc=t..ceiling_unit
else
	if translate==1 then unlset=additional.Unl else unlset=t end
tc=unlset
end
now["ceiling"]=tc
now["ceiling_caps"]=string.upper(tc)
now["ceiling_lc"]=string.lower(tc)
--get heat index
local s,f,t=string.find(nowweather,">Heat Index: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["heat_index"]=t
--get visibility
local s,f,t=string.find(nowweather,">Visibility: </a></td>%s*<td>([%a%d%p]*)</td>")
if t~="Unl" then
local s,f,t=string.find(t,"([%d%p]*)")
tv=t..visibility_unit
else
	if translate==1 then unlset=additional.Unl else unlset=t end
tv=unlset
end
now["visibility"]=tv
now["visibility_caps"]=string.upper(tv)
--get dew point
local s,f,t=string.find(nowweather,">Dew Point: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["dew_point"]=t
--get wind speed
local s,f,t=string.find(nowweather,">Wind: </a></td>%s*<td>(%d*)mph</td>")
local tmph=tonumber(t)
now["wind_mph"]=t..wind_mph_unit
now["wind_mph_caps"]=string.upper(t..wind_mph_unit)
--convert mph to km and knots
now["wind_km"]=round(tonumber(t)*1.609)..wind_km_unit
now["wind_km_caps"]=string.upper(round(tonumber(t)*1.609)..wind_km_unit)
now["wind_kts"]=round(tonumber(t)*0.869)..wind_kts_unit
now["wind_kts_caps"]=string.upper(round(tonumber(t)*0.869)..wind_kts_unit)
local s,f,t=string.find(nowweather,">Humidity: </a></td>%s*<td>(%d*)</td>")
now["humidity"]=t
--get wind direction ------------------------
local s,f,twd=string.find(nowweather,">Direction: </a></td>%s*<td style=[%p%a]*>([%d&;%s%(%a%)]*)</td>%s*</tr>")
--check for NA
local a,b,t=string.find(twd,"(%a*)")
local tnesw=t
if tnesw~="NA" then
local a,b,t=string.find(twd,"(%d*)&deg;")
now["wind_deg"]=t..wind_degrees_unit
local a,b,tnesw=string.find(twd,"%((%a*)%)")
	if tmph>0 and tmph<19 then
	now["wind_icon"]=weathericons.."green_"..string.lower(tnesw)..".png"
	elseif tmph>18 and tmph<38 then
	now["wind_icon"]=weathericons.."yellow_"..string.lower(tnesw)..".png"
	elseif tmph>37 and tmph<64 then
	now["wind_icon"]=weathericons.."orange_"..string.lower(tnesw)..".png"
	elseif tmph>63 then
	now["wind_icon"]=weathericons.."green_"..string.lower(tnesw)..".png"
	end
now["wind_font"]=windfontt[tnesw]
	if translate==1 then
	tnesw=neswtext[tnesw]
	else
	tnesw=tnesw
	end
now["wind_nesw"]=tnesw		
else
	if translate==1 then naset=additional.NA else naset="NA" end
now["wind_deg"]=naset
now["wind_icon"]=weathericons.."no_wind.png"
now["wind_nesw"]=naset
now["wind_font"]=windfontt["N"]
end
--END WIND DIRECTION #######################################################
--get pressure
local s,f,t=string.find(nowweather,">Pressure: </a></td>%s*<td>([%d%p]*)\"</td>")
now["pressure"]=t
--convert pressures ----------------
now["pressure_mb"]=round(tonumber(t)*33.86)
local s,f,t=string.find(nowweather,">Gusts: </a></td>%s*<td>([%d%a]*)</td>")
if t~="NA" then
local s,f,t=string.find(t,"(%d*)")
tg=t..wind_mph_unit
tgkm=round(tonumber(t)*1.609)..wind_km_unit
tgkts=round(tonumber(t)*0.869)..wind_kts_unit
else
	if translate==1 then naset=additional.NA else naset="NA" end
tg=naset
tgkm=naset
tgkts=naset
end
now["wind_gusts"]=tg
now["wind_gusts_caps"]=string.upper(tg)
now["wind_gusts_km"]=tgkm
now["wind_gusts_km_caps"]=string.upper(tgkm)
now["wind_gusts_kts"]=tgkts
now["wind_gusts_kts_caps"]=string.upper(tgkts)
--get hourly forecast options hour1
--get day 1 bit
local s,f,hfc=string.find(nowweather,"<td class=%pHour%p%sstyle=%ppadding%pleft([%a%d%p%s]*)%pdeg%p</strong>",1)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",1)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",1)
--24 hour conversion
now["fc_hour1_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour1_time"]=tm
now["fc_hour1_ampm"]=suf
now["fc_hour1_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%p%s%a]*)%s*</td>%s*<td class=%pHour%p",1)
now["fc_hour1_cond"]=t
now["fc_hour1_cond_lc"]=string.lower(t)
now["fc_hour1_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour1_cond_short"]=cons
	now["fc_hour1_cond_short_caps"]=string.upper(cons)
	now["fc_hour1_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",1)
now["fc_hour1_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour1_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)&deg;</strong></td>",1)
now["fc_hour1_temp"]=t
--end of hour1 data gathering--repeat 2 more times
--get hourly forecast options hour2--------------------
local start=tonumber(b)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",start)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",start)
--24 hour conversion
now["fc_hour2_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour2_time"]=tm
now["fc_hour2_ampm"]=suf
now["fc_hour2_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%a%s%p]*)%s*</td>%s*<td class=%pHour%p",start)
now["fc_hour2_cond"]=t
now["fc_hour2_cond_lc"]=string.lower(t)
now["fc_hour2_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour2_cond_short"]=cons
	now["fc_hour2_cond_short_caps"]=string.upper(cons)
	now["fc_hour2_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",start)
now["fc_hour2_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour2_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)&deg;</strong></td>",start)
now["fc_hour2_temp"]=t
--end of hour2 data gathering--repeat 1 more times
local start=tonumber(b)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",start)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",start)
--24 hour conversion
now["fc_hour3_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour3_time"]=tm
now["fc_hour3_ampm"]=suf
now["fc_hour3_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%a%s%p]*)%s*</td>%s*<td class=%pHour%p",start)
now["fc_hour3_cond"]=t
now["fc_hour3_cond_lc"]=string.lower(t)
now["fc_hour3_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour3_cond_short"]=cons
	now["fc_hour3_cond_short_caps"]=string.upper(cons)
	now["fc_hour3_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",start)
now["fc_hour3_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour3_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)",start)
now["fc_hour3_temp"]=t
--end of hour3 data gathering--finished for all hours
--ALERTS###############################################################
if alert_check==1 then
--set tables
alert_type={}
alert_issued={}
if alerttest~=0 then
alert_icon=weathericons.."icon_alert_1.gif"
--extract information into tables
local start=0
local f=1
while f~=nil do
local s,f,t=string.find(alertdata,"><strong class='Alert'>([%a%s]*)</strong><br/>",start)
	if t~=nil then
	table.insert(alert_type,string.upper(t))
	end--if t~=nil
local s,f,t=string.find(alertdata,"<br />([%d%a%s:]*)<br /><br />",start)
	if t~=nil then
	table.insert(alert_issued,t)
	end--if t~=nil
if f==nil then break end
start=f
alert_number=#alert_type
end--while
else
alert_icon=weathericons.."icon_alert_0.gif"
table.insert(alert_type,"NO ALERTS")
table.insert(alert_issued,"")
alert_number=0
end--alerttest~=nil
else
alert_type={}
alert_issued={}
alert_icon=weathericons.."icon_alert_0.gif"
table.insert(alert_type,"alerts turned off")
table.insert(alert_issued,"")
alert_number=0
end--if alert check
-- end of data processing
if testing==0 then
processall=0
print ("processing complete")
elseif testing==1 then
processall=1
end--if testing ==0
end--of data processing section
if processall==0 or testing==1 then
_G.weather_script()
end
--#########################################################################################################
--###UNCOMMENT THE BELOW LINE TO ENABLE CPU DELAY##########################################################
--end--####### end of if updates>5 #############################
--#########################################################################################################
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

function round(num)
	local idp=tonumber(settings_table[5])
	local mult = 10^(idp or 0)
	return math.floor(num * mult + 0.5) / mult
end--of round function

function string:split(delimiter)
local result = { }
local from  = 1
local delim_from, delim_to = string.find( self, delimiter, from  )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from  = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from  )
end
table.insert( result, string.sub( self, from  ) )
return result
end--string split


function xout(txj)
c=nil
a=nil
f=nil
fs=nil
x=nil
y=nil
txt=nil
j=nil

c=(txj.c or default_color)
a=(txj.a or default_alpha)
f=(txj.f or default_font)
fs=(txj.fs or default_font_size)
x=(txj.x or 0)
y=(txj.y or 0)
txt=(txj.txt or "set txt")
j=(txj.j or "l")

local cs=txj.cs     or default_size         or "normal_c"
local format=txj.format					or default_format			or "normal"
local ul=txj.ul     or default_ul         or "no"
local shaded=txj.shaded				or default_shaded		or "no"
------------------
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
local text=string.gsub(txt," ","_")
extents=cairo_text_extents_t:create()
cairo_text_extents(cr,text,extents)
local wx=extents.width
if j=="l" then
cairo_move_to (cr,x,y)
adx=wx
elseif j=="c" then
cairo_move_to (cr,x-(wx/2),y)
adx=wx/2
elseif j=="r" then
cairo_move_to (cr,x-wx,y)
adx=0
end
------------------------------------------------------------------------
cairo_select_font_face (cr, f, font_slant(format),font_weight(format));
------------------------------------------------------------------------
if cs=="big_c" then
txt=string.upper(txt)
elseif cs=="small_c" then
txt=string.lower(txt)
elseif cs=="normal_c" then
txt=txt
end
------------------------------------------------------------------------
	if ul=="yes" then
		lw=1
		lc=CAIRO_LINE_CAP_BUTT
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE)
		----------------------------
		startx=x
		endx=startx+wx
		starty=y+5
		endy=y+5
		----------------------------
		cairo_set_line_width (cr,lw)
		cairo_set_line_cap  (cr, lc)
		cairo_set_source_rgba (cr,col(c,a))
		cairo_show_text (cr,txt)
		cairo_move_to (cr,x,starty)
		cairo_line_to (cr,x+wx,endy)
		cairo_stroke (cr)
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT) 
	elseif ul == "no" then
		txt=txt
	end -- if
	-----------------------------------------------------
	if shaded == "yes" then
		sc=0x000000
		sa=1
		cairo_move_to (cr,(x + 1),(y + 1))
		cairo_set_source_rgba (cr,col(sc,sa))
		cairo_show_text (cr,txt)
		cairo_stroke (cr)
	elseif shaded=="no" then
	txt=txt
	end
	----------------------------------------------------
cairo_move_to (cr,(x),(y))
cairo_set_source_rgba (cr,col(c,a))
cairo_show_text (cr,txt)
cairo_stroke (cr)
nextx=nil
nextx=adx+x
return nextx
end--function xout

-- all following functions are working stand-alone
-- they can be copied because they do not have any dependance to work

function out(txj) -- function to output text
	local extents=cairo_text_extents_t:create()
	tolua.takeownership(extents)
	local blurred=nil
	local c=txj.c						or default_color		or 0xffffff
	local a=txj.a						or default_alpha		or 1
	local f=txj.f						or default_font			or "mono"
	local fs=txj.fs						or default_font_size	or 12
	local x=txj.x						or 100
	local y=txj.y						or 100
	local txt=txj.txt					or "set txt"
	local face=txj.face					or default_face			or "normal"
	local size=txj.size     			or default_size         or "normal_c"
	--------------------------------------------------------------------
	local hj=txj.hj						or default_hj			or "l"
	--------------------------------------------------------------------
	local shaded=txj.shaded				or default_shaded		or "no"
	local shade_color=txj.shade_color	or default_shade_color	or 0x000000
	local shade_alpha=txj.shade_alpha	or default_shade_alpha	or 1
	--------------------------------------------------------------------
	local underline=txj.underline     	or default_underline    or "no"
	local line_color=txj.line_color    	or   default_line_color or   c
	local line_space=txj.line_space    	or default_line_space   or  5
	local line_width=txj.line_width     or default_line_width   or  1
	--------------------------------------------------------------------
	local number=txj.number  or 8
	local radius=txj.radius or 1.75
	local blurred=txj.blurred or no
	local blurred_color=txj.blurred_color or c
	local blurred_alpha=txj.blurred_alpha or 1
	--------------------------------------------------------------------
	local border=txj.border
	local bc=txj.bc or 0x000000
	local ba=txj.ba or 1
	local bw=txj.bw or 1
	--------------------------------------------------------------------
	cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	----------------------
	if size=="big_c" then
	txt=string.upper(txt)
	elseif size=="small_c" then
	txt=string.lower(txt)
	elseif size=="normal_c" then
	txt=txt
	end
	----------------------
	cairo_set_font_size (cr, fs)
	cairo_text_extents(cr,txt,extents)
	local wx=extents.x_advance -- measure spaces too
	local wd=extents.width
	local hy=extents.height
	local bx=extents.x_bearing
	local by=extents.y_bearing+hy
	local tx=x
	local ty=y
	--set horizontal alignment
	if hj=="l" then
		x=x-bx
	elseif hj=="c" then
		x=x-((wx-bx)/2)-bx
	elseif hj=="r" then
		x=x-wx
	end
	if shaded == "yes" then
		cairo_move_to (cr,(x + 1),(y + 1))
		cairo_set_source_rgba (cr,col(shade_color,shade_alpha))
		cairo_show_text (cr,txt)
		cairo_stroke (cr)
	end -- if
	-------------------------------------------------
	cairo_move_to (cr,x,y)
	cairo_set_source_rgba (cr,col(c,a))
	cairo_show_text (cr,txt)
	cairo_stroke (cr)
	--------------------------------------------------
	if border=="yes" then
    cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	cairo_set_font_size (cr, fs);
	cairo_move_to (cr, x, y);
	cairo_text_path (cr,txt);
	cairo_set_source_rgba (cr,col(c,a));
	cairo_fill_preserve (cr);
	cairo_set_source_rgba (cr,col(bc,ba));
	cairo_set_line_width (cr, bw);
	cairo_stroke (cr);
	end

	-- #################################################################
	-- ## decrease alpha if u want to use a small size #################
	-- ## for example fs=12,blurred="yes",ba=0.1 #######################
	-- #################################################################
	if blurred=="yes" then
	 radi,inum,horiz,verti=radius,number,x,y
	
	 for i=1,inum do
	 deg=360/inum
	 text_arc=((2*math.pi/inum)*i)
	 txs=0+radi*(math.sin(text_arc))
	 tys=0-radi*(math.cos(text_arc))
	 -------------------------------------------------------------------
	 cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	 -------------------------------------------------------------------
	 cairo_set_font_size (cr, fs);
	 cairo_set_source_rgba (cr, col(blurred_color,blurred_alpha));
	 cairo_move_to (cr, txs+horiz, tys+verti);
	 cairo_show_text (cr, txt)
     end
	 
	elseif blurred=="no" then
	 txt=txt
	end
	--------------------------------------------------
		if string.find(underline,"yes") ~= nil then
		line_cap=CAIRO_LINE_CAP_BUTT
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE)
		----------------------------------------------
		startx=x
		endx=startx+wd
		starty=y+line_space
		endy=y+line_space
		-- draw line beyond text ---------------------
		cairo_set_line_width (cr,line_width)
		cairo_set_line_cap  (cr, line_cap)
		cairo_set_source_rgba (cr,col(line_color,a))
		cairo_move_to (cr,x,starty)
		cairo_line_to (cr,x+wd,endy)
		cairo_stroke (cr)
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT) --# reset antialiasing so we don't screw up other code
		elseif string.find(underline,"no") ~= nil then
		txt=txt
		end
	--------------------------------------------------------

end--of function out 

function font_slant(value)
 	fs=nil
 	
 	if value=="normal" then
	fs=CAIRO_FONT_SLANT_NORMAL
    elseif value=="bold" then
	fs=CAIRO_FONT_SLANT_NORMAL
	elseif value=="italic" then
	fs=CAIRO_FONT_SLANT_ITALIC
    elseif value=="bolditalic" then
    fs=CAIRO_FONT_SLANT_ITALIC
	elseif value=="oblique" then 
    fs=CAIRO_FONT_SLANT_OBLIQUE
	end
	    
	return fs
end

function font_weight(value)
	fw=nil
	
 	if string.find(value,"normal") ~= nil then
	fw=CAIRO_FONT_WEIGHT_NORMAL
    elseif value=="bold" then
	fw=CAIRO_FONT_WEIGHT_BOLD
	elseif value=="italic" then
	fw=CAIRO_FONT_WEIGHT_NORMAL
    elseif value =="bolditalic" then
    fw=CAIRO_FONT_WEIGHT_BOLD
	elseif string.find(value,"oblique") ~= nil then 
    fw=CAIRO_FONT_WEIGHT_NORMAL
	end
	    
	return fw
end



-- #####################################################################
-- ## convert 12h-format into 24h-format ###############################
-- #####################################################################

function convert24(tm,suf)
local tmlen=string.len(tm) -- calculate the length of a string
local colon=string.find(tm,":") -- find character within a string
	if colon~=nil then
	tmhr=string.sub(tm,1,colon-1)
	tmmn=string.sub(tm,colon+1,tmlen)
	else
	tmhr=tm
	tmmn=""
	end
if suf=="PM" and tonumber(tmhr)~=12 then
tmhr=tmhr+12
elseif suf=="PM" and tonumber(tmhr)==12  then
tmhr=12
elseif suf=="AM" and tonumber(tmhr)<10 then
tmhr="0"..tmhr
elseif suf=="AM" and tonumber(tmhr)>=10 and tonumber(tmhr)~=12 then
tmhr=tmhr
elseif suf=="AM" and tonumber(tmhr)==12 then
tmhr="00"
end
if colon~=nil then
return tmhr..":"..tmmn
else
return tmhr
end--if colon~=nil
end--of function

-- #####################################################################
-- ## END OF ORIGINAL SCRIPT ###########################################
-- #####################################################################

function m2n(mn)
--[[
function converts the name of the month into numbers
tonumber -> change type of a value (into a number)
]]--
------------------------------------------------------------------------
local m2n_input=nil
local m2n_input=mn.input or 0
local m2n_input=string.lower(m2n_input) -- convert text into lowercase to match the 'table-entries'
local m2n_lang=nil
local m2n_lang=mn.l or "en"
local month_to_num={} -- initalize table (array)
local output=nil
------------------------------------------------------------------------
if m2n_lang=="de" then
 month_to_num={"januar","februar","märz","april","mai","juni","juli","august","september","oktober","november","dezember"}
elseif m2n_lang=="it" then
 month_to_num={"gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre"}
elseif m2n_lang=="en" then
--May
 month_to_num={"january","february","march","april","may","june","juli","august","september","octobre","november","december"}
end
------------------------------------------------------------------------
for i,v in ipairs(month_to_num) do
    if tostring(m2n_input)==tostring(v) then
       if tonumber(i)<=9 then
	   output="0"..tonumber(i)
	   elseif tonumber(i)>=10 then
	   output=tonumber(i)
	   end
	end
end--of loop
return output
end--of function


-- #####################################################################
-- ## display external and local images ################################
-- #####################################################################

function image(im) -- display local images
	local x = nil
	local y = nil
	local w = nil	
	local h = nil
	local file = nil
	
	x =im.x or 0
	y =im.y or 0
	w =im.w or default_image_width -- default width is defined within the template
	h =im.h or default_image_height -- default height is defined within the template

	file = tostring(im.file)
	if file == nil then print("set image file") end 
	local show = imlib_load_image(file)
	if show == nil then return end --# if show == nil then 
	imlib_context_set_image(show)
	local WIDTH = nil
	if tonumber(w) == 0 then 
		WIDTH = imlib_image_get_width() 
	else
		WIDTH = tonumber(w)
	end -- if
	local HEIGHT = nil
	if tonumber(h) == 0 then HEIGHT = imlib_image_get_height() else HEIGHT = tonumber(h) end --# if tonumber(h) == 0 then 
	local scaled = imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), WIDTH, HEIGHT)
	imlib_free_image_and_decache()
	imlib_context_set_image(scaled)
	imlib_render_image_on_drawable(x, y)
	imlib_free_image_and_decache()
	show = nil
	WIDTH = nil
	HEIGHT = nil
	x = nil
	y = nil
	w = nil
	h = nil
	file = nil
	scaled = nil
end --# function

function extern(wb)
--[[
display external images (i.a. webcams)
extern({posx=0,posy=0,imgw=250,imgh=250,imgurl="http://www.gco.org.au/sky.jpg",imghdd="opensky.jpg",imgiv=60})
]]--
	local img_nw=nil
	local img_x=nil
	local img_y=nil
	local s=nil
	local j=nil
	local img_w=nil
	local img_h=nil
	local imgwidth=nil
	local imgheight=nil
	local imgt=nil
	local imgw=nil
	local imgh=nil
	--------------------------------------------------------------------
	img_x=wb.posx or 0 -- horizontal postion
	img_y=wb.posy or 0 -- vertical position
	img_w,imgh=wb.imgw,wb.imgh -- image width + height
	j=wb.j or "l" -- justification
	scaled=wb.scaled or "no" -- scale image or use default value
	scale_size=wb.scale_size or 200 -- set scaled width or use default value
	
	img_nw=wb.imghdd or "external_img.jpg" -- set name of the image
	s=wb.imgurl -- url of the external image (webcam etc.)
	img_file='/home/'..username.."/"..img_nw -- define storage location
	img_intervall=wb.imgiv or 60 -- set intervall
	
	-- grab external image from url and save it to hdd
	local updates = tonumber(conky_parse('${updates}'))
	if (math.mod(updates, img_intervall) == 0) then
		os.execute("wget  -q -O "..img_file..' "'..s..'"')
	end
	-- print error message when no image is defined
	if img_file==nil then print("set image file") end
	--------------------------------------------------------------------
	if scaled=="yes" then
		local show = imlib_load_image(img_file)
		if show == nil then return 	end
		imlib_context_set_image(show) -- display defined image if image file exists
		imgwidth= imlib_image_get_width() -- get image width
		imgheight=imlib_image_get_height() -- get image height
		imgw=scale_size
		imgh=(imgw*imgheight)/imgwidth
		imlib_free_image_and_decache() -- remove from cache
	else
		imgw=img_w
		imgh=img_h
	end
	-- set alignment ---------------------------------------------------
	if j=="l" then -- justify left
	 img_x=img_x
	elseif j=="r" then -- justify right
	 img_x=img_x-imgw
	end
	--------------------------------------------------------------------
	image({x=img_x,y=img_y,w=imgw,h=imgh,file=img_file}) -- load image, function image() must exist
end--of function


-- #####################################################################
-- ## functions to modify conky-output #################################
-- #####################################################################

function os_capture(cmd, raw) -- parse shell in lua
	local f = assert(io.popen(cmd, 'r'))
	local s = assert(f:read('*a'))
	f:close()
	if raw then return s end
	s = string.gsub(s, '^%s+', '')
	s = string.gsub(s, '%s+$', '')
	s = string.gsub(s, '[\n\r]+', ' ')
	return s
end



function parseValue(value,value1,value2,del,ending) -- remove ending and add custom ending
	jn=value:gsub(value1,"") 
	if ending=="no" then mv=chgFormat(jn,ending) else mv=chgFormat(jn,ending)..' '..value2 end
return mv
end


function nounit(var,ending,value)
	if var=="no" then ms=value else ms=value.." "..ending end
	return ms
end


function chgFormat(number,ending) --replace decimal point with ,
point=string.find(number,"%p")
if point~=nil then
n1=string.sub(number,1,point-1)
n2=string.sub(number,point,string.len(number))
n2=string.gsub(n2,"^.",",")

	if string.len(n2)==2 then
	n2=n2..""
	elseif string.len(n2)>3 then
	n2=string.sub(n2,1,3)	
	end
else
n1=number
n2=",0"
end

--put in divisions
n1len=string.len(n1)
divs=math.floor((n1len-1)/3)
if n1len>3 then
	for i=1,divs do
	n=n1len-(i*3)
	bit1=string.sub(n1,1,n)
	bit2=string.sub(n1,n+1)
	n1=bit1.."."..bit2
	end
end
output=n1..n2

return output
end

function chgDel(value,del)

local ausgang=nil
local ersteZahl=nil
local rest=nil
local outputNumber=nil

ausgang=string.gsub(value, "(%d*\.*%d+).*", "%1") -- remove ending
ausgang=tonumber(ausgang)

if not ausgang then ausgang=0; end

 if ((ausgang >= 10000) and (ausgang <= 99999.99)) then ----------------
       ersteZahl=string.sub(ausgang,1,2)
       rest=string.sub(ausgang,3,string.len(ausgang))
       
       if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",",")
	   else
	   outputNumber=ersteZahl..','..string.gsub(tostring(rest),"%,",".")
       end
       
 elseif ((ausgang>=1000) and (ausgang <9999.99)) then ------------------
       ersteZahl=string.sub(ausgang,1,1)
       rest=string.sub(ausgang,2,string.len(ausgang))
       
	   if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",del)
	   elseif del=="." then
	   outputNumber=ersteZahl..','..rest
       end
       
 elseif ausgang<999 then  ----------------------------------------------
	   if del=="," then
       outputNumber=string.gsub(tostring(ausgang),"%.",',')
	   elseif del=="." then
	   outputNumber=ausgang
       end
       
 elseif ausgang >=100000 then ------------------------------------------
	   
       ersteZahl=string.sub(ausgang,1,3)
       rest=string.sub(ausgang,4,string.len(ausgang))
       
	   if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",del)
	   elseif del=="." then
	   outputNumber=ersteZahl..','..rest
       end
       -----------------------------------------------------------------
 end

return outputNumber

end -- of function


function add_decimal(input,sign)  -- add decimal place, i.e. 5,0
if string.find(input,"%a")==nil then -- look for string
        if string.find(input,"%p")==nil then         -- only add decimal place when value is a number
        input=input..sign..'0'
        end
end
return input
end

function parse(value,delimiter,ending)
--[[
modify of conky-output
13.5GIB   chg format  13,5 gb
]]--

	local ms=nil
	value = value:gsub(" ","") --# remove spaces to account for inconsistencies in the inclusion of spaces in the output of different conky objects.
	if value==nil then value=0 end
	
	---- short_units no ------------------------------------------------
	if ((string.find(value, "iB") == nil) and (string.find(value, "B") ~= nil)) then
		ms=parseValue(value,"B",e1,delimiter,ending)
	elseif string.find(value, 'KiB') ~= nil then
		ms=parseValue(value,"KiB",e2,delimiter,ending)
	elseif string.find(value, 'MiB') ~= nil then
		ms=parseValue(value,"MiB",e3,delimiter,ending)
	elseif string.find(value, 'GiB') ~= nil then
		ms=parseValue(value,"GiB",e4,delimiter,ending)
	elseif string.find(value, "TiB") ~= nil then
		ms=parseValue(value,"TiB",e5,delimiter,ending)
	---- short_units yes -----------------------------------------------
	elseif ((string.find(value, "iB") == nil) and (string.find(value, "B") ~= nil)) then
		ms=parseValue(value,"B",e1,delimiter,ending)
	elseif string.find(value, "K") ~= nil then
		ms=parseValue(value,"K",e2,delimiter,ending)
	elseif string.find(value, "M") ~= nil then
		ms=parseValue(value,"M",e3,delimiter,ending)
	elseif string.find(value, "G") ~= nil then
		ms=parseValue(value,"G",e4,delimiter,ending)
	elseif string.find(value, "T") ~= nil then
		ms=parseValue(value,"T",e5,delimiter,ending)
	else
		ms=value:gsub(" ","") -- remove space
	end

	return ms
end -- of function


function system(cd)
--[[
variable -> argument for example fs_free
device --> system-device for example wlan0
del --> delimiter of number
tf --> format of shown time for example 01:15 uhr or 1:15 pm
se --> shown ending for example 1.000 mb or 1.000
dt --> show current date

you can call the function like this (example):
system({variable="totaldown",device="wlan0",del=',',se="no"})
]]--

local t=nil

local variable=cd.variable
local device=cd.device or ''
local del=cd.del or '.'
local tf=cd.tf or '24'
local se=cd.se or "yes"
local txt=cd.txt or "yes"
local dt=cd.dt or "no"

rawdata=conky_parse("${"..variable..' '..device.."}")
adv=parse(rawdata,del,se)

	if string.find(variable,"cpu") ~= nil then
		ms=nounit(se,e6,rawdata)
	elseif string.find(variable,"uptime") ~= nil or string.find(variable,"user_number") ~= nil then
		ms=rawdata
	elseif ((string.find(variable, "perc") ~= nil) or (string.find(variable, "percent") ~= nil)) then
	--------------------------------------------------------------------	
		if string.find(variable, "fs") ~= nil then
		ms=conky_parse("${if_mounted "..device.."}"..nounit(se,e6,rawdata).."${else}"..t3.."${endif}")
		else ms=nounit(se,e6,rawdata) end
	--------------------------------------------------------------------
	elseif ((string.find(variable,"freq") ~= nil) and (string.find(variable,"_g") == nil)) then
		jn=chgDel(adv,del)
		ms=nounit(se,e7,jn)
	elseif ((string.find(variable,"freq") ~= nil) and (string.find(variable,"_g") ~= nil)) then
		jn=chgDel(adv,del)
		ms=nounit(se,e8,add_decimal(jn,del))
	elseif string.find(variable,"loadavg") ~= nil then
		ms=rawdata
	--------------------------------------------------------------------
	elseif string.find(variable,"wireless_bitrate") ~= nil then
		t=rawdata:gsub("Mb/s","")
		t=chgDel(t,del)
		t=add_decimal(t,del)
		t=t:gsub(" ","") -- remove spaces
		ms=conky_parse("${if_up "..device.."}"..nounit(se,e9,t).."${else}"..t4.."${endif}")
	elseif string.find(variable,"wireless_essid") ~= nil or string.find(variable,"wireless_mode") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..rawdata.."${else}"..t4.."${endif}")
	elseif string.find(variable,"wireless_link_qual") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..nounit(se,e6,adv).."${else}"..t4.."${endif}")
	elseif string.find(variable,"upspeedf") ~= nil or string.find(variable,"downspeedf") ~= nil then
		jn=chgDel(adv,del) -- chg format
		ms=conky_parse("${if_up "..device.."}"..nounit(se,e10,add_decimal(jn,del)).."${else}"..t4.."${endif}")
	elseif string.find(variable,"battery") ~= nil then
		ms=rawdata
	--------------------------------------------------------------------
	elseif string.find(variable,"up") == nil and string.find(variable,"time") ~= nil then
		

if dt=="yes" then
ms=nounit(se,"",adv)
ms=ms:gsub(" ","")
else

if tf == "24" then ms=nounit(se,e11,adv) elseif tf == "12" then ms=convert12(rawdata,tf) end 

end

--[[
%B name of the month
%m month number, for example 05
%y year short number, for example 13
%Y year long number, for example 2013
%d day number
]]--

	else
	--------------------------------------------------------------------
		if string.find(device,"wlan") ~= nil or string.find(device,"eth") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..adv.."${else}"..t4.."${endif}")
		elseif string.find(device,"media") ~= nil then
		  --------------------------------------------------------------
          if txt=="no" and string.find(variable,"free") ~= nil then
           ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..t3.."${endif}")
          elseif txt=="yes" and string.find(variable,"free") ~= nil then
           ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t1.."${else}"..t3.."${endif}")

		  elseif txt=="no" and string.find(variable,"used") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..t3.."${endif}")
		  elseif txt=="yes" and string.find(variable,"used") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t2.."${else}"..t3.."${endif}")
		   
		  elseif txt=="no" and string.find(variable,"size") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..t3.."${endif}")
		  elseif txt=="yes" and string.find(variable,"size") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t5.."${else}"..t3.."${endif}")
		   
		  end
		  --------------------------------------------------------------
		else ms=adv  end 
	--------------------------------------------------------------------
	end

	return ms
end -- of function

-- convert 24h-format into 12h-format, for example 16:00 -> 4:00 pm
function convert12(value,format) 

local stunden=nil
local minuten=nil
local zeit=nil
local sekunden=nil

local stunden=string.sub(value,1,2) 	-- hours
local stunden=tonumber(stunden) 		-- convert hours into numbers
local minuten=string.sub(value,4,5)	 	-- minutes
local sekunden=string.sub(value,7,8) 	-- seconds

-- still calculate if string doesn't exists
if not sekunden then sekunden=''; end

if stunden > 12 and stunden < 24 then
	if sekunden ~= '' then
	zeit=(stunden-12)..':'..minuten..':'..sekunden..' pm'
	elseif sekunden == '' then
	zeit=(stunden-12)..':'..minuten..' pm'
	end
elseif stunden < 12 then
	if sekunden ~= '' then
	zeit=stunden..':'..minuten..':'..sekunden..' am'
	elseif sekunden == '' then
	zeit=stunden..':'..minuten..' am'
	end
elseif stunden == 12 then
	if sekunden ~= '' then
	zeit=stunden..':'..minuten..':'..sekunden..' pm'
	elseif sekunden == '' then
	zeit=stunden..':'..minuten..' pm'
	end
elseif stunden == 24 or stunden == 0 then
	if sekunden ~= '' then
	zeit=(stunden-12)..':'..minuten..':'..sekunden..' am'
	elseif sekunden == '' then
	zeit=(stunden-12)..':'..minuten..' am'
	end
end

return zeit

end


function dropZero(wert) -- drop leading charcacter

local ausgabe=nil
local erstezahl=tonumber(string.sub(wert,1,1))

 if erstezahl == 0 then
 ausgabe=string.sub(wert,2,5)
 else
 ausgabe=string.sub(wert,1,5)
 end -- of if

return ausgabe

end -- of function


function draw_bar(db) -- draw simple bar
------------------------------------------------------------------------
local var=nil
local dev=nil
local width=nil
local height=nil
local across=nil
local down=nil
local bgc=nil
local bga=nil
local inc=nil
local ina=nil
local lc=nil
local la=nil
local lw=nil
local rotate=nil
local justify=nil
------------------------------------------------------------------------
var=db.var
m=db.max or 100
dev=db.dev or ""
width,height=db.w,db.h
across,down=db.x,db.y
bgc,inc,lc=db.bgc,db.indc,db.lc
------------------------------------------------------------------------
bga=db.bga or 1
ina=db.inda or 1
la=db.la or 1
------------------------------------------------------------------------
lw=db.lw
rotate=db.r or 0
justify=db.j or "l"
------------------------------------------------------------------------
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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
------------------------------------------------------------------------
if updates>5 then -- starts the display

--indicator calculation
if not dev then dev=''; end

conum=conky_parse("${"..var..' '..dev.."}")
conum=tonumber(conum)

local inum=(((width-lw)/100)*(conum or 0))
local x =  100 * inum / m

-- justify bar
if justify=="r" then across=across-width elseif justify=="l" then across=across end

-- background bar ------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_source_rgba (cr, col(bgc, bga));
cairo_rectangle (cr, 0, 0, (width-lw), (height-lw))
cairo_fill (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
--indicator bar --------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_source_rgba (cr, col(inc,ina));
cairo_rectangle (cr, 0, 0, x, (height-lw))
cairo_fill (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
--boundary line --------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_line_width (cr, lw);
cairo_set_source_rgba (cr, col(lc,la));
cairo_rectangle (cr, -lw/2, -lw/2, width, height)
cairo_stroke (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
	end
end

-- ################################################
-- ## umwandeln von zahlen in wörter ########################
-- ################################################

function n2w(number)
--by mrpeachy 11-4-2012
local n1_tab={}
local n2_tab={}
number=tonumber(number)
local n_len=string.len(number)
if number<0 then
number=tonumber(string.sub(number,2,n_len))
minus="minus "
else
number=number
minus=""
end
if number>99 then
h=tonumber(string.sub(number,1,1))
tu=tonumber(string.sub(number,2,3))
t=tonumber(string.sub(number,2,2))
u=tonumber(string.sub(number,3,3))
elseif number<100 then
tu=number
t=tonumber(string.sub(number,1,1))
u=tonumber(string.sub(number,2,2))
end
n1_tab={"eins","zwei","drei","vier","fünf","sechs","sieben","acht","neun","zehn","elf","zwölf","dreizehn","vierzehn","fünfzehn","sechzehn","siebzehn","achtzehn","neunzehn",}
n2_tab={"zehn","zwanzig","dreißig","vierzig","fünfzig","sechzig","siebzig","achtzig","neunzig"}
if number>0 then n0="" else n0="null" end
if tu<20 and tu~=10 and tu~=0 then 
	ausgabe=n1_tab[tu]
elseif tu==10 then
	ausgabe="zehn"
elseif tu==0 then
	ausgabe="null"
elseif tu>19 then
	if u>0 then 
	joinu=" " 
	u=n1_tab[u]
	else 
	joinu=""
	u=""
	end
	g=string.sub(number,2,2)
	ausgabe=international(tu,g,n2_tab[t])
--	out=n2_tab[t]..joinu..u -- original
end
if number>99 and number~=100 then
	h=n1_tab[h]
	return minus..h.." hundred and "..ausgabe
elseif number==100 then
	return "einhundert"
elseif number<100 then
	return minus..ausgabe
end
end--function

function international(lang,geschnitten,wort)
local nummer=nil
local kurzezahl=nil

local anzahl=tonumber(lang)
local kurzezahl=tonumber(geschnitten)

if kurzezahl==1 or anzahl==1 then

 if string.len(anzahl)>1  then
 nummer='einund'..n2_tab[t]     -- gives me for example 21, 31 etc
 elseif string.len(anzahl)==1 then
 nummer='eins'			        -- gives me the number 1
 end

elseif kurzezahl~=1 or anzahl ~=1 then

   if anzahl==0 then
   nummer=wort                                     -- should give me the word 'null' (zero)
   elseif tonumber(string.sub(anzahl,1,1)) and tonumber(string.sub(anzahl,2,2))==0 then   --
   nummer=wort                                     -- gives me numbers like 10,20,30 etc.
   else 
    nummer=n2w(kurzezahl)..'und'..wort         --  gives me such numbers like 22,23,24 etc.
    end

end

return nummer

end -- der fun ktion

-- #####################################################################
-- ## end of functions to modify conky-output ##########################
-- #####################################################################


-- #####################################################################
-- ## gimmicks #########################################################
-- #####################################################################

function get_image() -- grab url of the 'image of the day' by the nasa 
	local uri='http://www.nasa.gov/rss/image_of_the_day.rss' -- address of rss-file 
	local f = assert(io.popen('curl -s '..uri, 'r')) -- get content of the rss-file
	local s = assert(f:read('*a'))
	f:close()
	s, f = string.gsub(s, ".*image\/jpeg.*(http://.*\.jpg).*", "%1")
	return s
end


function potw_uri() --  grab url of the 'picture of the week' by hubble 
	local uri = 'http://feeds.feedburner.com/hubble_potw?format=xml'
	local f = assert(io.popen('curl -s '..uri, 'r'))
	local s = assert(f:read('*a'))
	f:close()
	local b = nil
	local e = nil
	b,e,s = string.find(s,'(http://www%.spacetelescope%.org/static/archives/images/news/potw%d-.%.jpg)')
	return(s)
end

--END OF SCRIPT

the curious fact is that it works when i use an external device. this is the code from the template:

acgEV4uM.jpg

out({x=posx_3a,y=posy+60,c=dunkel,txt='home-folder:'})
out({x=posx_3b,y=posy+60,c=hell,txt=system({variable="fs_free_perc",device="/home/alexander"}),hj='r'})

out({x=posx_3a,y=posy+75,c=dunkel,txt='externe hdd:'})
out({x=posx_3b,y=posy+75,c=hell,txt=system({variable="fs_free_perc",device="/media/Elements"}),hj='r'})

out({x=posx_3a,y=posy+90,c=dunkel,txt='usb-stick:'})
out({x=posx_3b,y=posy+90,c=hell,txt=system({variable="fs_free_perc",device="/media/DD23-11E9"}),hj='r'})

sometimes an error-message occurs when i start my conky via console:

Conky: statfs64 'home/alexander': No such file or directory

the funny thing i that i declare the directory /home/alexander

edit: i've found the solution. just declare: /home

Last edited by lionhead (2013-05-31 09:26:31)

Offline

#5471 2013-06-01 11:00:29

easysid
#! CrunchBanger
From: India
Registered: 2013-01-25
Posts: 150

Re: Conky v1.9 Thread

My new setup
8911104368_e24e277106_m.jpg

compiz, awn and conky.

flowers.lua

--[[ 
flowers.lua for flowers conky
written by easysid 
Fri 31 May 2013 17:03:39 IST
]]--

require 'cairo'


function conky_flowers_main()
    t = {
    { 
        xc = 110, --placement
        yc = 170,
        size = 120, --size of petal.
        radius = 16, --radius of centre circle
        label = 'cpu',
        args = { 
        --[[ 1 for each petal in clockwise manner, starting from top left petal. 
         Specify the full conky variable. 
         You can skip any number of them by passing any non nil value
         (e.g '  ', '.' etc.), at its place.
         ]]--  
           '${cpu cpu0}%',
           '${cpu cpu1}%',
           '${cpu cpu2}%',
           '${cpu cpu3}%',
        },
        font_name = "monofur", -- for label and values
        label_font_size = 16, --label
        value_font_size = 14, --values
        bg_color = {0xd1d1d1, 0.7}, -- petals
        fg_color = {0x41a317, 0.6}, -- centre
        label_color = {0xd3d3d3, 0.8}, -- label
        value_color = {0x254117,0.9}, -- values
    },
    { 
        xc = 240,
        yc = 250,
        size = 120,
        radius = 18,
        label = 'temp',
        args = {
        '${platform coretemp.0 temp 2}°',
        '${platform coretemp.0 temp 4}°',
        '${execi 10 aticonfig --odgt | grep Temp | cut -c 43-44}°',
        '${execi 10 hddtemp /dev/sda -n }°'
        },
        font_name = "monofur",
        label_font_size = 14.5, --label
        value_font_size = 14, --values
        bg_color = {0xd1d1d1, 0.7}, -- petals
        fg_color = {0xF01210, 0.6}, -- centre
        label_color = {0xd3d3d3, 0.8}, -- text
        value_color = {0x981234,0.8}, --values
    },
    
    { 
        xc = 130,
        yc = 330,
        size = 120,
        radius = 16,
        label = 'mem',
        args = {
        '${memperc}%',
        '${fs_used_perc /}%',
        '${fs_used_perc /home}%',
        '${fs_used_perc /media/DATA}%',
        },
        font_name = "monofur",
        label_font_size = 16,
        value_font_size = 14,
        bg_color = {0xd1d1d1, 0.7}, -- petals
        fg_color = {0x735aff, 0.6}, -- centre
        label_color = {0xd3d3d3, 0.8}, -- text
        value_color = {0x4611af,0.9},
    },

    { 
        xc = 260,
        yc = 410,
        size = 120,
        radius = 17,
        label = 'misc',
        args = {
        '${battery_short BAT0}',
        '${if_existing /proc/net/route wlan0}net${else}off${endif}',
        "${execi 30 amixer get Master | grep '%' | cut -c 22-23}%",
        '${execi 10 cat /sys/class/backlight/acpi_video0/brightness}',
        },
        font_name = "monofur",
        label_font_size = 14,
        value_font_size = 14,
        bg_color = {0xd1d1d1, 0.7}, -- petals
        fg_color = {0xb93b8f, 0.6}, -- centre
        label_color = {0xd3d3d3, 0.8}, -- text
        value_color = {0x7d1b7e,0.9},
    },
}-- end t

    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)
    cr = cairo_create(cs)
    local updates=tonumber(conky_parse('${updates}'))
    if updates>3 then
        for i in ipairs(t) do
            flower_power(cr,t[i])
        end --for
    end --endif
    cairo_destroy(cr)
    cairo_surface_destroy(cs)
    cr=nil
end --end main()



function flower_power(cr,t)    

        for i in ipairs(t.args) do
            t.args[i] = conky_parse(t.args[i])
        end 
    -- start drawing
    cairo_set_source_rgba (cr, rgba_to_r_g_b_a(t.bg_color))
    cairo_set_line_width (cr, 2.0)
    -- top_left leaf   
    cairo_move_to (cr, t.xc, t.yc);    
    cairo_curve_to (cr, t.xc, t.yc-t.size, t.xc-t.size, t.yc, t.xc, t.yc)
    -- top_right leaf
    cairo_curve_to (cr, t.xc, t.yc-t.size, t.xc+t.size, t.yc, t.xc, t.yc)
    -- bottom_right leaf    
    cairo_curve_to (cr, t.xc, t.yc+t.size, t.xc+t.size, t.yc, t.xc, t.yc)    
    -- bottom_left leaf
    cairo_curve_to (cr, t.xc, t.yc+t.size, t.xc-t.size, t.yc, t.xc, t.yc)

    cairo_fill(cr)
    
    -- Draw the centre circle
    cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR) --clear the area
    cairo_arc(cr, t.xc, t.yc, t.radius, 0, 2*math.pi) 
    cairo_fill(cr)
    cairo_set_operator(cr,CAIRO_OPERATOR_OVER) --draw the circle
    cairo_set_source_rgba (cr, rgba_to_r_g_b_a(t.fg_color))
    cairo_arc(cr, t.xc, t.yc, t.radius, 0, 2*math.pi) 
    cairo_fill(cr)
    
    -- Place label. See the out() function for details.
    out({x=t.xc, y=t.yc, text=t.label, color=t.label_color,
     font=t.font_name, fs=t.label_font_size, centred=true})
    
    --Place values
    local dx = 4 -- these are scaling factors
    local dy = 4 -- change here for text adjustments
    out({x=t.xc-t.size/dx, y=t.yc-t.size/dy, text=t.args[1],
     color=t.value_color, font=t.font_name, fs=t.value_font_size,
      centred=true, bold=true})
    out({x=t.xc+t.size/dx, y=t.yc-t.size/dy, text=t.args[2],
     color=t.value_color, font=t.font_name, fs=t.value_font_size,
      centred=true, bold=true})
    out({x=t.xc+t.size/dx, y=t.yc+t.size/dy, text=t.args[3],
     color=t.value_color, font=t.font_name, fs=t.value_font_size,
      centred=true, bold=true})
    out({x=t.xc-t.size/dx, y=t.yc+t.size/dy, text=t.args[4],
     color=t.value_color, font=t.font_name, fs=t.value_font_size,
      centred=true, bold=true})

end -- end flower_power


function out(t)
    --[[ function to put the text
    arguments:
    x,y - position of the text (bottom-left) -mandatory
    text - text to display
    
    optional arguments:
    font - font face
    fs - font size
    color - color in {hexvalue, alpha} pair
    bold - boolean. default false. Bold text
    italic - boolean. default false
    centred - boolean. default false. Centre the text at x,y instead of starting from it.    
    ]]--
    
    -- checks
    t.font = t.font or 'monospace'
    t.fs = t.fs or 14
    t.color = t.color or {0xffffff,1}
    t.text = t.text or 'text'
    t.centred = t.centred or false
    t.bold = t.bold and CAIRO_FONT_WEIGHT_BOLD or CAIRO_FONT_WEIGHT_NORMAL
    t.italic = t.italic and CAIRO_FONT_SLANT_ITALIC or CAIRO_FONT_SLANT_NORMAL

    if t.centred then
        local ext = cairo_text_extents_t:create()
        cairo_text_extents(cr,t.text,ext)
        t.x = t.x - ext.width/2
        t.y = t.y + ext.height/4
    end
    --setup   
    cairo_set_source_rgba (cr, rgba_to_r_g_b_a(t.color))
    cairo_select_font_face (cr, t.font, t.italic, t.bold)
    cairo_set_font_size (cr, t.fs)
    --print
    cairo_move_to(cr,t.x,t.y)
    cairo_show_text(cr,t.text)

end -- end out


function rgba_to_r_g_b_a(tcolor)
    local color,alpha=tcolor[1],tcolor[2]
    return ((color / 0x10000) % 0x100) / 255., 
        ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end --end rgba

Thanks to dk75 suggesting the text_extents. Also, I wrote a ripoff of mrpeachy's out function to place the text. I previously had a small offset to separate the petals at the centre, but as I ended up passing offset=0 in all cases,  I removed it. All the above made the code a whole lot cleaner. There's still a bit of hand hacking :8. Look for the lines local dx = 4 local dy = 4 . These are just convenient scaling factors to place the text. You may need to fiddle with them.

----
EDIT  11-April-2014 If you are coming here from the Conky Archives Thread, grab the code from https://github.com/easysid/conky_configs smile
----

Last edited by easysid (2014-04-11 11:27:33)

Offline

#5472 2013-06-01 15:50:56

lionhead
#! Junkie
From: Dagobah / Germany
Registered: 2011-01-22
Posts: 459

Re: Conky v1.9 Thread

i have some problems with my script. sometimes i display empty spaces (see photo). in the first image you can see en empty space behind the sign %

http://postimg.com/image/143000/2013-06 … 142712.jpg

and here (behind the word 'unmounted'):

http://postimg.com/image/143000/2013-06 … 142714.jpg

and here the code:

-- weather v9000 by mrpeachy 01/10/12; released: Feb 29, 2012
-- official update by mrpeachy
-- additional features by lionhead, arclance and dk75
-- optimize lua: http://lua-users.org/wiki/OptimizedStrRep
-- last update 01.06.2013

require 'cairo'
require 'imlib2'
local username = os.getenv("USERNAME")

--you can enter your username here in case of errors, 
--enter username in quotes like this username = "yourname"
local username = "alexander"

-- you need to translate this text
local t1="frei" -- when u use fs_free or fs_free_perc
local t2="belegt" -- when u use fs_size
local t3="not mounted" -- display text when hardrive/usb-stick is unmounted
local t4="n/a" -- display text when internet connection is not avaiable
local t5="gesamt" -- when u use fs_used or fs_used_perc
local t6="verbleibend" -- remaining

-- customize ending
local e1="byte"
local e2="kb"
local e3="mb"
local e4="gb"
local e5="tb"
local e6="%"
local e7="mhz"
local e8="ghz"
local e9="mb/s"
local e10="kb/s"
local e11="uhr"

package.path = '/home/'..username..'/.v9000_config.lua'
require '.v9000_config'

-- #####################################################################
-- ## end of translation ###############################################
-- #####################################################################

start=1
--INITIALIZE SETTINGS-- need only be run once
settings_table=weather_settings()
--##################################
--######## main function ########### 
function conky_weather()--##########
-- function to convert color into hex-code
function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function

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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
--###UNCOMMENT THE BELOW LINE TO ENABLE CPU DELAY##########################################################
--if updates>5 then--###### YOU WILL ALSO HAVE TO UNCOMMENT THE MATCHING end ON LINE 923 ####################
--#########################################################################################################
local testing=0--this setting is for script testing, if not in testing set to 0
--#########################################################################################################
--############start of timed section#######################################################################
--#########################################################################################################
local timer=(updates %tonumber(settings_table[1]))
if timer==0 or start==1 then--######
start=nil--#######################################
local web=settings_table[2]
local alert_check=settings_table[13]
print ("gathering data with curl")
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
allweatherdata=f:read("*a")
f:close()
allweatherdata=string.gsub(allweatherdata,"[\n\r]","")
testall=string.find(allweatherdata,">10 Day Forecast&nbsp")
--CHECK FOR WEATHER ALERTS
if testall~=nil and alert_check==1 then
local alert=string.find(allweatherdata,"Severe Weather Alert!")
	if alert~=nil then
	print ("getting weather alerts")
	--get alert web
	local a,b,alertchunk=string.find(allweatherdata,">Local Information</div>(.*)>Severe Weather Alert!<")
	local a,b,alertsite=string.find(alertchunk,"><a href=%p(.*)%p><img src=")
	local f=io.popen("curl --max-time 60 'http://www.intellicast.com"..alertsite.."' | sed 's/%//g'")
	alertdata=f:read("*a")
	f:close()
	alertdata=string.gsub(alertdata,"[\n\r]","")
	alerttest=string.find(alertdata,"%a")
	else
	print ("you have no weather alerts")
	alerttest=0
	end--if alert~=nil
else
print ("not checking for alerts")
alerttest=1
end--if testall and alert check
processall=1
end--of timed data gathering section
--in case curl craps up it should retry until it works
if testall==nil or  alerttest==nil then
print ("curl attempt timed out, trying again")
local web=settings_table[2]
local alert_check=settings_table[13]
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
allweatherdata=f:read("*a")
f:close()
allweatherdata=string.gsub(allweatherdata,"[\n\r]","")
testall=string.find(allweatherdata,">10 Day Forecast&nbsp")
--CHECK FOR WEATHER ALERTS
if testall~=nil and alert_check==1 then
local alert=string.find(allweatherdata,"Severe Weather Alert!")
	if alert~=nil then
	print ("getting weather alerts")
	--get alert web
	local a,b,alertchunk=string.find(allweatherdata,">Local Information</div>(.*)>Severe Weather Alert!<")
	local a,b,alertsite=string.find(alertchunk,"><a href=%p(.*)%p><img src=")
	local f=io.popen("curl --max-time 60 'http://www.intellicast.com"..alertsite.."' | sed 's/%//g'")
	alertdata=f:read("*a")
	f:close()
	alertdata=string.gsub(alertdata,"[\n\r]","")
	alerttest=string.find(alertdata,"%a")
	else
	print ("you have no weather alerts")
	alerttest=0
	end--if alert~=nil
else
print ("not checking for alerts")
alerttest=1
end--if testall and alert_check
processall=1
end--if testall==nil
--end or curl reruns
--START PROCESSING ###########################################################################
if testall~=nil and alerttest~=nil and processall==1 then
local weathericons=settings_table[3]
local con_short=settings_table[4]
local visibility_unit=settings_table[6]
local wind_mph_unit=settings_table[7]
local wind_km_unit=settings_table[8]
local wind_kts_unit=settings_table[9]
local ceiling_unit=settings_table[10]
local wind_degrees_unit=settings_table[11]
local translate=settings_table[12]
local alert_check=settings_table[13]
--LOAD TRANSLATE TABLES IF TRANSLATE SETTING = 1
	if translate==1 then
	monthshort=settings_table[21]
	monthnames=settings_table[20]
	dayhort=settings_table[19]
	daynames=settings_table[18]
	neswtext=settings_table[14]
	tsuffix=settings_table[15]
	uvindextext=settings_table[16]
	moonphases=settings_table[17]
	additional=settings_table[22]
	else--neswtext,tsuffix,uvindextext,moonphases,daynames,dayshort,monthnames,monthshort

	dayshort={Monday="Mon",Tuesday="Tue",Wednesday="Wed",Thursday="Thu",Friday="Fri",Saturday="Sat",Sunday="Sun"}
	monthshort={January="Jan",February="Feb",March="Mar",April="Apr",May="May",June="Jun",July="Jul",August="Aug",September="Sep",October="Oct",November="Nov",December="Dec"}
	end--end if translate =1
--process data tables
--intellicast to conky weather icon conversion
wimage={
wx_65="32",  -- Clear
wx_66="30",  -- Partly Cloudy
wx_67="26",  -- Cloudy
wx_68="32",  -- Clear
wx_69="28",  -- Mostly Cloudy
wx_70="20",  -- Fog
wx_71="32",  -- Clear
wx_72="21",  -- Haze
wx_73="36",  -- Hot
wx_74="14",  -- Light Snow Showers
wx_75="28",  -- Mostly Cloudy
wx_76="18",  -- Sleet
wx_77="14",  -- Light Snow Showers
wx_78="23",  -- Blustery
wx_79="05",  -- Mixed Rain and Snow
wx_80="15",  -- Drifting Snow
wx_81="15",  -- Drifting Snow
wx_82="11",  -- Light Rain
wx_83="16",  -- Snow
wx_84="00",  -- Tornado
wx_85="32",  -- Clear
wx_86="25",  -- N/A
wx_87="09",  -- Drizzle
wx_88="05",  -- Mixed Rain and Snow
wx_89="18",  -- Sleet
wx_90="18",  -- Sleet
wx_91="39",  -- Scattered Showers
wx_92="39",  -- Scattered Showers
wx_93="39",  -- Scattered Showers
wx_94="39",  -- Scattered Showers
wx_95="37",  -- Isolated Thunderstorms
wx_96="37",  -- Isolated Thunderstorms
wx_97="31",  -- Clear
wx_98="29",  -- Partly Cloudy
wx_99="27",  -- Mostly Cloudy
wx_100="47",  -- Isolated Thunderstorms
wx_101="47",  -- Isolated Thunderstorms
wx_102="33",  -- Fair
wx_103="26",  -- Cloudy
wx_104="20",  -- Fog
wx_105="45",  -- Scattered Showers
wx_106="45",  -- Scattered Showers
wx_107="11",  -- Light Rain
wx_108="46",  -- Snow Showers
wx_109="46",  -- Snow Showers
wx_110="06",  -- Mixed Rain and Sleet
wx_111="18",  -- Sleet
wx_112="06",  -- Mixed Rain and Sleet
wx_113="46",  -- Snow Showers
wx_114="46",  -- Snow Showers
wx_115="31",  -- Clear
wx_116="47",  -- Isolated Thunderstorms
}--end w image table
--convert intellicast icons to weather font
wfont={
wx_65="a",
wx_66="c",
wx_67="f",
wx_68="a",
wx_69="d",
wx_70="0",
wx_71="a",
wx_72="9",
wx_73="5",
wx_74="p",
wx_75="d",
wx_76="w",
wx_77="p",
wx_78="6",
wx_79="x",
wx_80="8",
wx_81="8",
wx_82="h",
wx_83="q",
wx_84="m",
wx_85="a",
wx_86="-",
wx_87="h",
wx_88="x",
wx_89="w",
wx_90="w",
wx_91="g",
wx_92="g",
wx_93="g",
wx_94="g",
wx_95="k",
wx_96="k",
wx_97="A",
wx_98="C",
wx_99="D",
wx_100="K",
wx_101="K",
wx_102="B",
wx_103="f",
wx_104="0",
wx_105="G",
wx_106="G",
wx_107="h",
wx_108="O",
wx_109="O",
wx_110="x",
wx_111="w",
wx_112="x",
wx_113="O",
wx_114="O",
wx_115="A",
wx_116="K",
}--end w font table
--conversion day and month tables
moonfontt={
["New"]="@",
["Full"]="=",
["First Quarter"]="T",
["Last Quarter"]="G",
["Waning Gibbous"]="D",
["Waning Crescent"]="J",
["Waxing Crescent"]="Q",
["Waxing Gibbous"]="W",
}--end of moon font table
moonicont={
["New"]=weathericons.."moon_new.png",
["Full"]=weathericons.."moon_full.png",
["First Quarter"]=weathericons.."moon_first_quarter.png",
["Last Quarter"]=weathericons.."moon_last_quarter.png",
["Waning Gibbous"]=weathericons.."moon_waning_gibbous.png",
["Waning Crescent"]=weathericons.."moon_waning_crescent.png",
["Waxing Crescent"]=weathericons.."moon_waxing_crescent.png",
["Waxing Gibbous"]=weathericons.."moon_waxing_gibbous.png",
}--end of moon icon table
windfontt={
S="9",
SSW=":",
SW=";",
WSW="<",
W="=",
WNW=">",
NW="?",
NNW="@",
N="1",
NNE="2",
NE="3",
ENE="4",
E="5",
ESE="6",
SE="7",
SSE="8"
}--end of wind direction font table
--setup tables for forecast weather
forecast_day={}
forecast_day_caps={}
forecast_day_lc={}
forecast_day_short={}
forecast_day_short_caps={}
forecast_day_short_lc={}
forecast_month={}
forecast_month_caps={}
forecast_month_lc={}
forecast_month_short={}
forecast_month_short_caps={}
forecast_month_short_lc={}
forecast_date={}
weather_icon={}
weather_font={}
high_temp={}
low_temp={}
conditions={}
conditions_caps={}
conditions_lc={}
conditions_short={}
conditions_short_caps={}
conditions_short_lc={}
sun_rise={}
sun_rise_lc={}
sun_rise_time={}
sun_rise_24={}
moon_rise={}
moon_rise_lc={}
moon_rise_time={}
moon_rise_24={}
moon_rise_ampm={}
moon_rise_ampm_lc={}
sun_set={}
sun_set_lc={}
sun_set_time={}
sun_set_24={}
moon_set={}
moon_set_lc={}
moon_set_time={}
moon_set_24={}
moon_set_ampm={}
moon_set_ampm_lc={}
humidity={}
precipitation={}
snow={}
cloud_cover={}
moon_phase={}
moon_phase_caps={}
moon_phase_lc={}
moon_font={}
moon_icon={}
wind_mph={}
wind_km={}
wind_kts={}
wind_font={}
wind_icon={}
wind_deg={}
wind_nesw={}
uv_index_num={}
uv_index_txt={}
uv_index_txt_caps={}
uv_index_txt_lc={}
--get forecast chunk --------------------------------------------------------
local a,b,allweather=string.find(allweatherdata,">10 Day Forecast&nbsp(.*)>More from Intellicast</div>")
--extract information into tables
local start=0
local f=1
while f~=nil do
--match forecast day name and date
local s,f,t=string.find(allweather,"<td colspan=\"2\"><strong>([%a,%s%d]*)</strong></td>",start)
	if t~=nil then
	--split name from month and date
	local a,b,day=string.find(t,"(%a*),%s")
	local a,b,month=string.find(t,",%s(%a*)%s")
	local a,b,date=string.find(t,"(%d*)$")
	--set day names, regular, caps, lowercase and short
	table.insert(forecast_day_short,dayshort[day])
	table.insert(forecast_day_short_caps,string.upper(dayshort[day]))
	table.insert(forecast_day_short_lc,string.lower(dayshort[day]))
		if translate==1 then
		day=daynames[day]
		else
		day=day
		end
	table.insert(forecast_day,day)
	table.insert(forecast_day_caps,string.upper(day))
	table.insert(forecast_day_lc,string.lower(day))
	--set month types
	table.insert(forecast_month_short,monthshort[month])
	table.insert(forecast_month_short_caps,string.upper(monthshort[month]))
	table.insert(forecast_month_short_lc,string.lower(monthshort[month]))
		if translate==1 then
		month=monthnames[month]
		else
		month=month
		end
	table.insert(forecast_month,month)
	table.insert(forecast_month_caps,string.upper(month))
	table.insert(forecast_month_lc,string.lower(month))
	--set date
	table.insert(forecast_date,date)
	end--if t~= nil
--intellicast weather icon match
local s,f,t=string.find(allweather,"40_white/(wx_[%d]*).png\"",start)
--convert to conkyweather icon
	if t~=nil then
	table.insert(weather_icon,weathericons..wimage[t]..".png")
	--convert to weather font
	table.insert(weather_font,wfont[t])
	end
--match conditions
local s,f,t=string.find(allweather," /><br />([%a%s%p]*)</td>",start)
	if t~=nil then
	table.insert(conditions,t)
	table.insert(conditions_caps,string.upper(t))
	table.insert(conditions_lc,string.lower(t))
	--set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	----------------------------------------------------
	table.insert(conditions_short,cons)
	table.insert(conditions_short_caps,string.upper(cons))
	table.insert(conditions_short_lc,string.lower(cons))
	end
--match high temp
local s,f,t=string.find(allweather,"\"Hi\">([%p%d]*)&deg",start)
table.insert(high_temp,t)
--match low temp
local s,f,t=string.find(allweather,"\"Lo\">([%p%d]*)&deg",start)
table.insert(low_temp,t)
--match sun rise times
local s,f,t=string.find(allweather,"Rise:</strong> (%d*:%d*%s%u%u)</td>",start)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(sun_rise_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(sun_rise,tm.." "..suf)
	table.insert(sun_rise_lc,string.lower(tm.." "..suf))
	table.insert(sun_rise_time,tm)
	end
--match sun set times
local s,f,t=string.find(allweather,"Set:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then	
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(sun_set_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(sun_set,tm.." "..suf)
	table.insert(sun_set_lc,string.lower(tm.." "..suf))
	table.insert(sun_set_time,tm)
	end
--moon rise
local s,f,t=string.find(allweather,"Rise:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(moon_rise_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(moon_rise,tm.." "..suf)
	table.insert(moon_rise_lc,string.lower(tm.." "..suf))
	table.insert(moon_rise_time,tm)
	table.insert(moon_rise_ampm,suf)
	table.insert(moon_rise_ampm_lc,string.lower(suf))
	end
--moon set
local s,f,t=string.find(allweather,"Set:</strong> (%d*:%d*%s%u%u)</td>",f)
	if t~=nil then
	--get time only
	local a,b,tm=string.find(t,"([%d%p]*)")
	--get suffix only
	local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
table.insert(moon_set_24,convert24(tm,suf))
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
	table.insert(moon_set,tm.." "..suf)
	table.insert(moon_set_lc,string.lower(tm.." "..suf))
	table.insert(moon_set_time,tm)
	table.insert(moon_set_ampm,suf)
	table.insert(moon_set_ampm_lc,string.lower(suf))
	end
--match uv index
local s,f,tuv=string.find(allweather,"UV Index:</strong>%s*(%d*%s*%([%a%s]*%))%s*<br />",start)
if tuv~=nil then
	--get just number
	local a,b,unm=string.find(tuv,"(%d*)%s*%([%a%s]*%)")
	--get just text
	local a,b,utx=string.find(tuv,"%d*%s*%(([%a%s]*)%)")
	table.insert(uv_index_num,unm)
		if translate==1 then
		utx=uvindextext[utx]
		else
		utx=utx
		end
	table.insert(uv_index_txt,utx)
	table.insert(uv_index_txt_caps,string.upper(utx))
	table.insert(uv_index_txt_lc,string.lower(utx))
	end
--match humidity
local s,f,t=string.find(allweather,"Humidity:</strong> (%d*)<br />",start)
table.insert(humidity,t)
--match ppt
local s,f,t=string.find(allweather,"Precipitation:</strong> (%d*)<br />",start)
table.insert(precipitation,t)
--match snow %
local s,f,t=string.find(allweather,"Snow Probability:</strong>%s*(%d*)<br />",start)
table.insert(snow,t)
--match cloud coverage
local s,f,t=string.find(allweather,"Cloud Coverage:</strong> (%d*)<br />",start)
table.insert(cloud_cover,t)
--match moon phase
local s,f,t=string.find(allweather,"Moon Phase:</strong> ([%a%s]*) <br />",start)
--set moon phase text
	if t~= nil then
	--set moon phase font and icon
	table.insert(moon_font,moonfontt[t])
	table.insert(moon_icon,moonicont[t])
		if translate==1 then
		t=moonphases[t]
		else
		t=t
		end
	table.insert(moon_phase,t)
	table.insert(moon_phase_caps,string.upper(t))
	table.insert(moon_phase_lc,string.lower(t))
	end
--match wind speeds
local s,f,tmph=string.find(allweather,"Wind Speed:</strong> (%d*)Mph",start)
local tmph=tonumber(tmph)
table.insert(wind_mph,tmph)
local s,f,t=string.find(allweather,"Mph%s*%((%d*)Km,",start)
table.insert(wind_km,t)
local s,f,t=string.find(allweather,"Km,%s*(%d*)Kts%)",start)
table.insert(wind_kts,t)
--match wind direction
local s,f,twd=string.find(allweather,"Wind Direction:</strong> ([%d&;%s%(%a%)]*)%s*</div>",start)
	if twd~=nil then
	local a,b,tdeg=string.find(twd,"(%d*)&deg;")
	table.insert(wind_deg,tdeg)
	--match wind font and nesw   
	local a,b,tnesw=string.find(twd,"%((%a*)%)")
	table.insert(wind_font,windfontt[tnesw])
		if tmph>0 and tmph<19 then
		table.insert(wind_icon,weathericons.."green_"..string.lower(tnesw)..".png")
		elseif tmph>18 and tmph<38 then
		table.insert(wind_icon,weathericons.."yellow_"..string.lower(tnesw)..".png")
		elseif tmph>37 and tmph<64 then
		table.insert(wind_icon,weathericons.."orange_"..string.lower(tnesw)..".png")
		elseif tmph>63 then
		table.insert(wind_icon,weathericons.."green_"..string.lower(tnesw)..".png")
		elseif tmph==0 then
		table.insert(wind_icon,weathericons.."no_wind.png")
		end
		if translate==1 then
		tnesw=neswtext[tnesw]
		else
		tnesw=tnesw
		end
	table.insert(wind_nesw,tnesw)
	end
if f==nil then break end
start=f
end--while
--get location
local a,b,wl=string.find(allweatherdata,"<title>%s*Intellicast%s%p%s(.*)</title>")
weather_location=string.gsub(wl," Extended Forecast in",",")
--format now weather
--extract current data
--get now weather chunk
local a,b,nowweather=string.find(allweatherdata,">Current Conditions&nbsp(.*)>View Detailed Observations for the last<br />")
now={}
monthlong={Jan="January",Feb="February",Mar="March",Apr="April",May="May",Jun="June",Jul="July",Aug="August",Sep="September",Oct="October",Nov="November",Dec="December"}
local s,f,tnow=string.find(nowweather,"<div style=\"float:right;color:#666;\">  As of ([%d%p%a%s]*) %(Local Time%)")
local s,f,t=string.find(tnow,"(%d*%p%d*%s%a*) on")
--get time only
local a,b,ntm=string.find(t,"(%d*%p%d*)")
--get suffix only
local a,b,suf=string.find(t,"(%u%u)")
--24 hour conversion
now["time_24"]=convert24(ntm,suf)
if translate==1 then
suf=tsuffix[suf]
else
suf=suf
end
now["time"]=ntm.." "..suf
now["time_lc"]=string.lower(ntm.." "..suf)
now["time_num"]=ntm
now["time_ampm"]=suf
now["time_ampm_lc"]=string.lower(suf)
--get day
local s,f,t=string.find(tnow,"on (%a*)%s%d*")
if translate==1 then
day=daynames[t]
else
day=t
end
now["day"]=day
now["day_caps"]=string.upper(day)
now["day_lc"]=string.lower(day)
--short day names
local ds=dayshort[t]
now["day_short"]=ds
now["day_short_caps"]=string.upper(ds)
now["day_short_lc"]=string.lower(ds)
--get date
local s,f,t=string.find(tnow,"%s(%d%d)%s")
now["date"]=t
--get months
local s,f,t=string.find(tnow,"%d%d%s(%a*)%s%d")
if translate==1 then
mnth=monthlong[t]
now["month_short"]=monthshort[mnth]
now["month_short_caps"]=string.upper(monthshort[mnth])
now["month_short_lc"]=string.lower(monthshort[mnth])
mnth=monthnames[mnth]
else
now["month_short"]=t
now["month_short_caps"]=string.upper(t)
now["month_short_lc"]=string.lower(t)
mnth=monthlong[t]
end
now["month"]=mnth
now["month_caps"]=string.upper(mnth)
now["month_lc"]=string.lower(mnth)
local s,f,t=string.find(tnow,"%a%a%a%s(%d%d%d%d)")
now["year"]=t
local s,f,t=string.find(nowweather,"40_white/(wx_[%d]*)%ppng%p%stitle=%p")
now["weather_icon"]=weathericons..wimage[t]..".png"
now["weather_font"]=wfont[t]
local s,f,t=string.find(nowweather,"class=%pIcon%p /> ([%a%s%p]*)%s*%s*</td>%s*<td class=%pEmpty%p>&nbsp;")
local t=t:gsub("^%s*(.-)%s*$", "%1")
now["conditions"]=t
now["conditions_caps"]=string.upper(t)
now["conditions_lc"]=string.lower(t)
--set short versions------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["conditions_short"]=cons
	now["conditions_short_caps"]=string.upper(cons)
	now["conditions_short_lc"]=string.lower(cons)
--------------------------------------------
local s,f,t=string.find(nowweather,"Temperature\">([%p%d]*)&deg")
now["temp"]=t
local s,f,t=string.find(nowweather,">Feels Like: ([%p%d]*)&deg;</a>")
now["feels_like"]=t
local s,f,t=string.find(nowweather,">Wind Chill: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["wind_chill"]=t
local s,f,t=string.find(nowweather,">Ceiling: </a></td>%s*<td>([%a%d]*)</td>")
if t~="Unl" then
local s,f,t=string.find(t,"([%d%p]*)")
tc=t..ceiling_unit
else
	if translate==1 then unlset=additional.Unl else unlset=t end
tc=unlset
end
now["ceiling"]=tc
now["ceiling_caps"]=string.upper(tc)
now["ceiling_lc"]=string.lower(tc)
--get heat index
local s,f,t=string.find(nowweather,">Heat Index: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["heat_index"]=t
--get visibility
local s,f,t=string.find(nowweather,">Visibility: </a></td>%s*<td>([%a%d%p]*)</td>")
if t~="Unl" then
local s,f,t=string.find(t,"([%d%p]*)")
tv=t..visibility_unit
else
	if translate==1 then unlset=additional.Unl else unlset=t end
tv=unlset
end
now["visibility"]=tv
now["visibility_caps"]=string.upper(tv)
--get dew point
local s,f,t=string.find(nowweather,">Dew Point: </a></td>%s*<td>([%p%d]*)&deg;</td>")
now["dew_point"]=t
--get wind speed
local s,f,t=string.find(nowweather,">Wind: </a></td>%s*<td>(%d*)mph</td>")
local tmph=tonumber(t)
now["wind_mph"]=t..wind_mph_unit
now["wind_mph_caps"]=string.upper(t..wind_mph_unit)
--convert mph to km and knots
now["wind_km"]=round(tonumber(t)*1.609)..wind_km_unit
now["wind_km_caps"]=string.upper(round(tonumber(t)*1.609)..wind_km_unit)
now["wind_kts"]=round(tonumber(t)*0.869)..wind_kts_unit
now["wind_kts_caps"]=string.upper(round(tonumber(t)*0.869)..wind_kts_unit)
local s,f,t=string.find(nowweather,">Humidity: </a></td>%s*<td>(%d*)</td>")
now["humidity"]=t
--get wind direction ------------------------
local s,f,twd=string.find(nowweather,">Direction: </a></td>%s*<td style=[%p%a]*>([%d&;%s%(%a%)]*)</td>%s*</tr>")
--check for NA
local a,b,t=string.find(twd,"(%a*)")
local tnesw=t
if tnesw~="NA" then
local a,b,t=string.find(twd,"(%d*)&deg;")
now["wind_deg"]=t..wind_degrees_unit
local a,b,tnesw=string.find(twd,"%((%a*)%)")
	if tmph>0 and tmph<19 then
	now["wind_icon"]=weathericons.."green_"..string.lower(tnesw)..".png"
	elseif tmph>18 and tmph<38 then
	now["wind_icon"]=weathericons.."yellow_"..string.lower(tnesw)..".png"
	elseif tmph>37 and tmph<64 then
	now["wind_icon"]=weathericons.."orange_"..string.lower(tnesw)..".png"
	elseif tmph>63 then
	now["wind_icon"]=weathericons.."green_"..string.lower(tnesw)..".png"
	end
now["wind_font"]=windfontt[tnesw]
	if translate==1 then
	tnesw=neswtext[tnesw]
	else
	tnesw=tnesw
	end
now["wind_nesw"]=tnesw		
else
	if translate==1 then naset=additional.NA else naset="NA" end
now["wind_deg"]=naset
now["wind_icon"]=weathericons.."no_wind.png"
now["wind_nesw"]=naset
now["wind_font"]=windfontt["N"]
end
--END WIND DIRECTION #######################################################
--get pressure
local s,f,t=string.find(nowweather,">Pressure: </a></td>%s*<td>([%d%p]*)\"</td>")
now["pressure"]=t
--convert pressures ----------------
now["pressure_mb"]=round(tonumber(t)*33.86)
local s,f,t=string.find(nowweather,">Gusts: </a></td>%s*<td>([%d%a]*)</td>")
if t~="NA" then
local s,f,t=string.find(t,"(%d*)")
tg=t..wind_mph_unit
tgkm=round(tonumber(t)*1.609)..wind_km_unit
tgkts=round(tonumber(t)*0.869)..wind_kts_unit
else
	if translate==1 then naset=additional.NA else naset="NA" end
tg=naset
tgkm=naset
tgkts=naset
end
now["wind_gusts"]=tg
now["wind_gusts_caps"]=string.upper(tg)
now["wind_gusts_km"]=tgkm
now["wind_gusts_km_caps"]=string.upper(tgkm)
now["wind_gusts_kts"]=tgkts
now["wind_gusts_kts_caps"]=string.upper(tgkts)
--get hourly forecast options hour1
--get day 1 bit
local s,f,hfc=string.find(nowweather,"<td class=%pHour%p%sstyle=%ppadding%pleft([%a%d%p%s]*)%pdeg%p</strong>",1)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",1)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",1)
--24 hour conversion
now["fc_hour1_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour1_time"]=tm
now["fc_hour1_ampm"]=suf
now["fc_hour1_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%p%s%a]*)%s*</td>%s*<td class=%pHour%p",1)
now["fc_hour1_cond"]=t
now["fc_hour1_cond_lc"]=string.lower(t)
now["fc_hour1_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour1_cond_short"]=cons
	now["fc_hour1_cond_short_caps"]=string.upper(cons)
	now["fc_hour1_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",1)
now["fc_hour1_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour1_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)&deg;</strong></td>",1)
now["fc_hour1_temp"]=t
--end of hour1 data gathering--repeat 2 more times
--get hourly forecast options hour2--------------------
local start=tonumber(b)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",start)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",start)
--24 hour conversion
now["fc_hour2_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour2_time"]=tm
now["fc_hour2_ampm"]=suf
now["fc_hour2_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%a%s%p]*)%s*</td>%s*<td class=%pHour%p",start)
now["fc_hour2_cond"]=t
now["fc_hour2_cond_lc"]=string.lower(t)
now["fc_hour2_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour2_cond_short"]=cons
	now["fc_hour2_cond_short_caps"]=string.upper(cons)
	now["fc_hour2_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",start)
now["fc_hour2_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour2_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)&deg;</strong></td>",start)
now["fc_hour2_temp"]=t
--end of hour2 data gathering--repeat 1 more times
local start=tonumber(b)
--get time and conditions
local a,b,tm=string.find(hfc,"<strong>([%d%p]*)[%s%a]*</strong><br",start)
local a,b,suf=string.find(hfc,"<strong>[%d%p%s]*([%a]*)</strong><br",start)
--24 hour conversion
now["fc_hour3_time_24"]=convert24(tm,suf)
		if translate==1 then
		suf=tsuffix[suf]
		else
		suf=suf
		end
now["fc_hour3_time"]=tm
now["fc_hour3_ampm"]=suf
now["fc_hour3_ampm_lc"]=string.lower(suf)
local a,b,t=string.find(hfc,"</strong><br%s/>%s*([%a%s%p]*)%s*</td>%s*<td class=%pHour%p",start)
now["fc_hour3_cond"]=t
now["fc_hour3_cond_lc"]=string.lower(t)
now["fc_hour3_cond_caps"]=string.upper(t)
----------set short versions--------------------------------
	local cons=t
        for k,v in pairs(con_short) do
            local cons_length=string.len(cons)
            local match_length=string.len(k)
            if cons_length==match_length then
            cons=string.gsub(cons,k,v)
            end
        end
	now["fc_hour3_cond_short"]=cons
	now["fc_hour3_cond_short_caps"]=string.upper(cons)
	now["fc_hour3_cond_short_lc"]=string.lower(cons)
--get weather icon and font
local a,b,t=string.find(hfc,"32_white/(wx_[%d]*)%ppng%p%stitle=%p",start)
now["fc_hour3_wicon"]=weathericons..wimage[t]..".png"
now["fc_hour3_wfont"]=wfont[t]
--get temperature
local a,b,t=string.find(hfc,"><strong>([%p%d]*)",start)
now["fc_hour3_temp"]=t
--end of hour3 data gathering--finished for all hours
--ALERTS###############################################################
if alert_check==1 then
--set tables
alert_type={}
alert_issued={}
if alerttest~=0 then
alert_icon=weathericons.."icon_alert_1.gif"
--extract information into tables
local start=0
local f=1
while f~=nil do
local s,f,t=string.find(alertdata,"><strong class='Alert'>([%a%s]*)</strong><br/>",start)
	if t~=nil then
	table.insert(alert_type,string.upper(t))
	end--if t~=nil
local s,f,t=string.find(alertdata,"<br />([%d%a%s:]*)<br /><br />",start)
	if t~=nil then
	table.insert(alert_issued,t)
	end--if t~=nil
if f==nil then break end
start=f
alert_number=#alert_type
end--while
else
alert_icon=weathericons.."icon_alert_0.gif"
table.insert(alert_type,"NO ALERTS")
table.insert(alert_issued,"")
alert_number=0
end--alerttest~=nil
else
alert_type={}
alert_issued={}
alert_icon=weathericons.."icon_alert_0.gif"
table.insert(alert_type,"alerts turned off")
table.insert(alert_issued,"")
alert_number=0
end--if alert check
-- end of data processing
if testing==0 then
processall=0
print ("processing complete")
elseif testing==1 then
processall=1
end--if testing ==0
end--of data processing section
if processall==0 or testing==1 then
_G.weather_script()
end
--#########################################################################################################
--###UNCOMMENT THE BELOW LINE TO ENABLE CPU DELAY##########################################################
--end--####### end of if updates>5 #############################
--#########################################################################################################
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

function round(num)
	local idp=tonumber(settings_table[5])
	local mult = 10^(idp or 0)
	return math.floor(num * mult + 0.5) / mult
end--of round function

function string:split(delimiter)
local result = { }
local from  = 1
local delim_from, delim_to = string.find( self, delimiter, from  )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from  = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from  )
end
table.insert( result, string.sub( self, from  ) )
return result
end--string split


function xout(txj)
c=nil
a=nil
f=nil
fs=nil
x=nil
y=nil
txt=nil
j=nil

c=(txj.c or default_color)
a=(txj.a or default_alpha)
f=(txj.f or default_font)
fs=(txj.fs or default_font_size)
x=(txj.x or 0)
y=(txj.y or 0)
txt=(txj.txt or "set txt")
j=(txj.j or "l")

local cs=txj.cs     or default_size         or "normal_c"
local format=txj.format					or default_format			or "normal"
local ul=txj.ul     or default_ul         or "no"
local shaded=txj.shaded				or default_shaded		or "no"
------------------
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
local text=string.gsub(txt," ","_")
extents=cairo_text_extents_t:create()
cairo_text_extents(cr,text,extents)
local wx=extents.width
if j=="l" then
cairo_move_to (cr,x,y)
adx=wx
elseif j=="c" then
cairo_move_to (cr,x-(wx/2),y)
adx=wx/2
elseif j=="r" then
cairo_move_to (cr,x-wx,y)
adx=0
end
------------------------------------------------------------------------
cairo_select_font_face (cr, f, font_slant(format),font_weight(format));
------------------------------------------------------------------------
if cs=="big_c" then
txt=string.upper(txt)
elseif cs=="small_c" then
txt=string.lower(txt)
elseif cs=="normal_c" then
txt=txt
end
------------------------------------------------------------------------
	if ul=="yes" then
		lw=1
		lc=CAIRO_LINE_CAP_BUTT
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE)
		----------------------------
		startx=x
		endx=startx+wx
		starty=y+5
		endy=y+5
		----------------------------
		cairo_set_line_width (cr,lw)
		cairo_set_line_cap  (cr, lc)
		cairo_set_source_rgba (cr,col(c,a))
		cairo_show_text (cr,txt)
		cairo_move_to (cr,x,starty)
		cairo_line_to (cr,x+wx,endy)
		cairo_stroke (cr)
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT) 
	elseif ul == "no" then
		txt=txt
	end -- if
	-----------------------------------------------------
	if shaded == "yes" then
		sc=0x000000
		sa=1
		cairo_move_to (cr,(x + 1),(y + 1))
		cairo_set_source_rgba (cr,col(sc,sa))
		cairo_show_text (cr,txt)
		cairo_stroke (cr)
	elseif shaded=="no" then
	txt=txt
	end
	----------------------------------------------------
cairo_move_to (cr,(x),(y))
cairo_set_source_rgba (cr,col(c,a))
cairo_show_text (cr,txt)
cairo_stroke (cr)
nextx=nil
nextx=adx+x
return nextx
end--function xout

-- all following functions are working stand-alone
-- they can be copied because they do not have any dependance to work

function out(txj) -- function to output text
	local extents=cairo_text_extents_t:create()
	tolua.takeownership(extents)
	local blurred=nil
	local c=txj.c						or default_color		or 0xffffff
	local a=txj.a						or default_alpha		or 1
	local f=txj.f						or default_font			or "mono"
	local fs=txj.fs						or default_font_size	or 12
	local x=txj.x						or 100
	local y=txj.y						or 100
	local txt=txj.txt					or "set txt"
	local face=txj.face					or default_face			or "normal"
	local size=txj.size     			or default_size         or "normal_c"
	--------------------------------------------------------------------
	local hj=txj.hj						or default_hj			or "l"
	--------------------------------------------------------------------
	local shaded=txj.shaded				or default_shaded		or "no"
	local shade_color=txj.shade_color	or default_shade_color	or 0x000000
	local shade_alpha=txj.shade_alpha	or default_shade_alpha	or 1
	--------------------------------------------------------------------
	local underline=txj.underline     	or default_underline    or "no"
	local line_color=txj.line_color    	or   default_line_color or   c
	local line_space=txj.line_space    	or default_line_space   or  5
	local line_width=txj.line_width     or default_line_width   or  1
	--------------------------------------------------------------------
	local number=txj.number  or 8
	local radius=txj.radius or 1.75
	local blurred=txj.blurred or no
	local blurred_color=txj.blurred_color or c
	local blurred_alpha=txj.blurred_alpha or 1
	--------------------------------------------------------------------
	local border=txj.border
	local bc=txj.bc or 0x000000
	local ba=txj.ba or 1
	local bw=txj.bw or 1
	--------------------------------------------------------------------
	cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	----------------------
	if size=="big_c" then
	txt=string.upper(txt)
	elseif size=="small_c" then
	txt=string.lower(txt)
	elseif size=="normal_c" then
	txt=txt
	end
	----------------------
	cairo_set_font_size (cr, fs)
	cairo_text_extents(cr,txt,extents)
	local wx=extents.x_advance -- measure spaces too
	local wd=extents.width
	local hy=extents.height
	local bx=extents.x_bearing
	local by=extents.y_bearing+hy
	local tx=x
	local ty=y
	--set horizontal alignment
	if hj=="l" then
		x=x-bx
	elseif hj=="c" then
		x=x-((wx-bx)/2)-bx
	elseif hj=="r" then
		x=x-wx
	end
	if shaded == "yes" then
		cairo_move_to (cr,(x + 1),(y + 1))
		cairo_set_source_rgba (cr,col(shade_color,shade_alpha))
		cairo_show_text (cr,txt)
		cairo_stroke (cr)
	end -- if
	-------------------------------------------------
	cairo_move_to (cr,x,y)
	cairo_set_source_rgba (cr,col(c,a))
	cairo_show_text (cr,txt)
	cairo_stroke (cr)
	--------------------------------------------------
	if border=="yes" then
    cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	cairo_set_font_size (cr, fs);
	cairo_move_to (cr, x, y);
	cairo_text_path (cr,txt);
	cairo_set_source_rgba (cr,col(c,a));
	cairo_fill_preserve (cr);
	cairo_set_source_rgba (cr,col(bc,ba));
	cairo_set_line_width (cr, bw);
	cairo_stroke (cr);
	end

	-- #################################################################
	-- ## decrease alpha if u want to use a small size #################
	-- ## for example fs=12,blurred="yes",ba=0.1 #######################
	-- #################################################################
	if blurred=="yes" then
	 radi,inum,horiz,verti=radius,number,x,y
	
	 for i=1,inum do
	 deg=360/inum
	 text_arc=((2*math.pi/inum)*i)
	 txs=0+radi*(math.sin(text_arc))
	 tys=0-radi*(math.cos(text_arc))
	 -------------------------------------------------------------------
	 cairo_select_font_face (cr, f, font_slant(face),font_weight(face));
	 -------------------------------------------------------------------
	 cairo_set_font_size (cr, fs);
	 cairo_set_source_rgba (cr, col(blurred_color,blurred_alpha));
	 cairo_move_to (cr, txs+horiz, tys+verti);
	 cairo_show_text (cr, txt)
     end
	 
	elseif blurred=="no" then
	 txt=txt
	end
	--------------------------------------------------
		if string.find(underline,"yes") ~= nil then
		line_cap=CAIRO_LINE_CAP_BUTT
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE)
		----------------------------------------------
		startx=x
		endx=startx+wd
		starty=y+line_space
		endy=y+line_space
		-- draw line beyond text ---------------------
		cairo_set_line_width (cr,line_width)
		cairo_set_line_cap  (cr, line_cap)
		cairo_set_source_rgba (cr,col(line_color,a))
		cairo_move_to (cr,x,starty)
		cairo_line_to (cr,x+wd,endy)
		cairo_stroke (cr)
		cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT) --# reset antialiasing so we don't screw up other code
		elseif string.find(underline,"no") ~= nil then
		txt=txt
		end
	--------------------------------------------------------

end--of function out 

function font_slant(value)
 	fs=nil
 	
 	if value=="normal" then
	fs=CAIRO_FONT_SLANT_NORMAL
    elseif value=="bold" then
	fs=CAIRO_FONT_SLANT_NORMAL
	elseif value=="italic" then
	fs=CAIRO_FONT_SLANT_ITALIC
    elseif value=="bolditalic" then
    fs=CAIRO_FONT_SLANT_ITALIC
	elseif value=="oblique" then 
    fs=CAIRO_FONT_SLANT_OBLIQUE
	end
	    
	return fs
end

function font_weight(value)
	fw=nil
	
 	if string.find(value,"normal") ~= nil then
	fw=CAIRO_FONT_WEIGHT_NORMAL
    elseif value=="bold" then
	fw=CAIRO_FONT_WEIGHT_BOLD
	elseif value=="italic" then
	fw=CAIRO_FONT_WEIGHT_NORMAL
    elseif value =="bolditalic" then
    fw=CAIRO_FONT_WEIGHT_BOLD
	elseif string.find(value,"oblique") ~= nil then 
    fw=CAIRO_FONT_WEIGHT_NORMAL
	end
	    
	return fw
end



-- #####################################################################
-- ## convert 12h-format into 24h-format ###############################
-- #####################################################################

function convert24(tm,suf)
local tmlen=string.len(tm) -- calculate the length of a string
local colon=string.find(tm,":") -- find character within a string
	if colon~=nil then
	tmhr=string.sub(tm,1,colon-1)
	tmmn=string.sub(tm,colon+1,tmlen)
	else
	tmhr=tm
	tmmn=""
	end
if suf=="PM" and tonumber(tmhr)~=12 then
tmhr=tmhr+12
elseif suf=="PM" and tonumber(tmhr)==12  then
tmhr=12
elseif suf=="AM" and tonumber(tmhr)<10 then
tmhr="0"..tmhr
elseif suf=="AM" and tonumber(tmhr)>=10 and tonumber(tmhr)~=12 then
tmhr=tmhr
elseif suf=="AM" and tonumber(tmhr)==12 then
tmhr="00"
end
if colon~=nil then
return tmhr..":"..tmmn
else
return tmhr
end--if colon~=nil
end--of function

-- #####################################################################
-- ## END OF ORIGINAL SCRIPT ###########################################
-- #####################################################################

function m2n(mn)
--[[
function converts the name of the month into numbers
tonumber -> change type of a value (into a number)
]]--
------------------------------------------------------------------------
local m2n_input=nil
local m2n_input=mn.input or 0
local m2n_input=string.lower(m2n_input) -- convert text into lowercase to match the 'table-entries'
local m2n_lang=nil
local m2n_lang=mn.l or "en"
local month_to_num={} -- initalize table (array)
local output=nil
------------------------------------------------------------------------
if m2n_lang=="de" then
 month_to_num={"januar","februar","märz","april","mai","juni","juli","august","september","oktober","november","dezember"}
elseif m2n_lang=="it" then
 month_to_num={"gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre"}
elseif m2n_lang=="en" then
--May
 month_to_num={"january","february","march","april","may","june","juli","august","september","octobre","november","december"}
end
------------------------------------------------------------------------
for i,v in ipairs(month_to_num) do
    if tostring(m2n_input)==tostring(v) then
       if tonumber(i)<=9 then
	   output="0"..tonumber(i)
	   elseif tonumber(i)>=10 then
	   output=tonumber(i)
	   end
	end
end--of loop
return output
end--of function


-- #####################################################################
-- ## display external and local images ################################
-- #####################################################################

function image(im) -- display local images
	local x = nil
	local y = nil
	local w = nil	
	local h = nil
	local file = nil
	
	x =im.x or 0
	y =im.y or 0
	w =im.w or default_image_width -- default width is defined within the template
	h =im.h or default_image_height -- default height is defined within the template

	file = tostring(im.file)
	if file == nil then print("set image file") end 
	local show = imlib_load_image(file)
	if show == nil then return end --# if show == nil then 
	imlib_context_set_image(show)
	local WIDTH = nil
	if tonumber(w) == 0 then 
		WIDTH = imlib_image_get_width() 
	else
		WIDTH = tonumber(w)
	end -- if
	local HEIGHT = nil
	if tonumber(h) == 0 then HEIGHT = imlib_image_get_height() else HEIGHT = tonumber(h) end --# if tonumber(h) == 0 then 
	local scaled = imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), WIDTH, HEIGHT)
	imlib_free_image_and_decache()
	imlib_context_set_image(scaled)
	imlib_render_image_on_drawable(x, y)
	imlib_free_image_and_decache()
	show = nil
	WIDTH = nil
	HEIGHT = nil
	x = nil
	y = nil
	w = nil
	h = nil
	file = nil
	scaled = nil
end --# function

function extern(wb)
--[[
display external images (i.a. webcams)
extern({posx=0,posy=0,imgw=250,imgh=250,imgurl="http://www.gco.org.au/sky.jpg",imghdd="opensky.jpg",imgiv=60})
]]--
	local img_nw=nil
	local img_x=nil
	local img_y=nil
	local s=nil
	local j=nil
	local img_w=nil
	local img_h=nil
	local imgwidth=nil
	local imgheight=nil
	local imgt=nil
	local imgw=nil
	local imgh=nil
	--------------------------------------------------------------------
	img_x=wb.posx or 0 -- horizontal postion
	img_y=wb.posy or 0 -- vertical position
	img_w,imgh=wb.imgw,wb.imgh -- image width + height
	j=wb.j or "l" -- justification
	scaled=wb.scaled or "no" -- scale image or use default value
	scale_size=wb.scale_size or 200 -- set scaled width or use default value
	
	img_nw=wb.imghdd or "external_img.jpg" -- set name of the image
	s=wb.imgurl -- url of the external image (webcam etc.)
	img_file='/home/'..username.."/"..img_nw -- define storage location
	img_intervall=wb.imgiv or 60 -- set intervall
	
	-- grab external image from url and save it to hdd
	local updates = tonumber(conky_parse('${updates}'))
	if (math.mod(updates, img_intervall) == 0) then
		os.execute("wget  -q -O "..img_file..' "'..s..'"')
	end
	-- print error message when no image is defined
	if img_file==nil then print("set image file") end
	--------------------------------------------------------------------
	if scaled=="yes" then
		local show = imlib_load_image(img_file)
		if show == nil then return 	end
		imlib_context_set_image(show) -- display defined image if image file exists
		imgwidth= imlib_image_get_width() -- get image width
		imgheight=imlib_image_get_height() -- get image height
		imgw=scale_size
		imgh=(imgw*imgheight)/imgwidth
		imlib_free_image_and_decache() -- remove from cache
	else
		imgw=img_w
		imgh=img_h
	end
	-- set alignment ---------------------------------------------------
	if j=="l" then -- justify left
	 img_x=img_x
	elseif j=="r" then -- justify right
	 img_x=img_x-imgw
	end
	--------------------------------------------------------------------
	image({x=img_x,y=img_y,w=imgw,h=imgh,file=img_file}) -- load image, function image() must exist
end--of function


-- #####################################################################
-- ## functions to modify conky-output #################################
-- #####################################################################

function os_capture(cmd, raw) -- parse shell in lua
	local f = assert(io.popen(cmd, 'r'))
	local s = assert(f:read('*a'))
	f:close()
	if raw then return s end
	s = string.gsub(s, '^%s+', '')
	s = string.gsub(s, '%s+$', '')
	s = string.gsub(s, '[\n\r]+', ' ')
	return s
end



function parseValue(value,value1,value2,del,ending) -- remove ending and add custom ending
	jn=value:gsub(value1,"") 
	if ending=="no" then mv=chgFormat(jn,ending) else mv=chgFormat(jn,ending)..' '..value2 end
return mv
end



function nounit(device,var,ending,value)
	if var=="no" then ms=value else ms=value.." "..ending end
	return ms
end

function snu(ending,ct,cn)
		if ending=="yes" then mv=cn.." "..ct else mv=cn end
		return mv
end

function dropSign(dev,sign)
ms=conky_parse("${if_mounted "..dev.."}"..sign.."${else}".."".."${endif}")
return ms
end


function chgFormat(number,ending) --replace decimal point with ,
point=string.find(number,"%p")
if point~=nil then
n1=string.sub(number,1,point-1)
n2=string.sub(number,point,string.len(number))
n2=string.gsub(n2,"^.",",")

	if string.len(n2)==2 then
	n2=n2..""
	elseif string.len(n2)>3 then
	n2=string.sub(n2,1,3)	
	end
else
n1=number
n2=",0"
end

--put in divisions
n1len=string.len(n1)
divs=math.floor((n1len-1)/3)
if n1len>3 then
	for i=1,divs do
	n=n1len-(i*3)
	bit1=string.sub(n1,1,n)
	bit2=string.sub(n1,n+1)
	n1=bit1.."."..bit2
	end
end
output=n1..n2

return output
end

function chgDel(value,del)

local ausgang=nil
local ersteZahl=nil
local rest=nil
local outputNumber=nil

ausgang=string.gsub(value, "(%d*\.*%d+).*", "%1") -- remove ending
ausgang=tonumber(ausgang)

if not ausgang then ausgang=0; end

 if ((ausgang >= 10000) and (ausgang <= 99999.99)) then ----------------
       ersteZahl=string.sub(ausgang,1,2)
       rest=string.sub(ausgang,3,string.len(ausgang))
       
       if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",",")
	   else
	   outputNumber=ersteZahl..','..string.gsub(tostring(rest),"%,",".")
       end
       
 elseif ((ausgang>=1000) and (ausgang <9999.99)) then ------------------
       ersteZahl=string.sub(ausgang,1,1)
       rest=string.sub(ausgang,2,string.len(ausgang))
       
	   if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",del)
	   elseif del=="." then
	   outputNumber=ersteZahl..','..rest
       end
       
 elseif ausgang<999 then  ----------------------------------------------
	   if del=="," then
       outputNumber=string.gsub(tostring(ausgang),"%.",',')
	   elseif del=="." then
	   outputNumber=ausgang
       end
       
 elseif ausgang >=100000 then ------------------------------------------
	   
       ersteZahl=string.sub(ausgang,1,3)
       rest=string.sub(ausgang,4,string.len(ausgang))
       
	   if del=="," then
       outputNumber=ersteZahl..'.'..string.gsub(tostring(rest),"%.",del)
	   elseif del=="." then
	   outputNumber=ersteZahl..','..rest
       end
       -----------------------------------------------------------------
 end

return outputNumber

end -- of function


function add_decimal(input,sign)  -- add decimal place, i.e. 5,0
if string.find(input,"%a")==nil then -- look for string
        if string.find(input,"%p")==nil then         -- only add decimal place when value is a number
        input=input..sign..'0'
        end
end
return input
end

function parse(value,delimiter,ending)
--[[
modify of conky-output
13.5GIB   chg format  13,5 gb
]]--

	local ms=nil
	value = value:gsub(" ","") --# remove spaces to account for inconsistencies in the inclusion of spaces in the output of different conky objects.
	if value==nil then value=0 end
	
	---- short_units no ------------------------------------------------
	if ((string.find(value, "iB") == nil) and (string.find(value, "B") ~= nil)) then
		ms=parseValue(value,"B",e1,delimiter,ending)
	elseif string.find(value, 'KiB') ~= nil then
		ms=parseValue(value,"KiB",e2,delimiter,ending)
	elseif string.find(value, 'MiB') ~= nil then
		ms=parseValue(value,"MiB",e3,delimiter,ending)
	elseif string.find(value, 'GiB') ~= nil then
		ms=parseValue(value,"GiB",e4,delimiter,ending)
	elseif string.find(value, "TiB") ~= nil then
		ms=parseValue(value,"TiB",e5,delimiter,ending)
	---- short_units yes -----------------------------------------------
	elseif ((string.find(value, "iB") == nil) and (string.find(value, "B") ~= nil)) then
		ms=parseValue(value,"B",e1,delimiter,ending)
	elseif string.find(value, "K") ~= nil then
		ms=parseValue(value,"K",e2,delimiter,ending)
	elseif string.find(value, "M") ~= nil then
		ms=parseValue(value,"M",e3,delimiter,ending)
	elseif string.find(value, "G") ~= nil then
		ms=parseValue(value,"G",e4,delimiter,ending)
	elseif string.find(value, "T") ~= nil then
		ms=parseValue(value,"T",e5,delimiter,ending)
	else
		ms=value:gsub(" ","") -- remove space
	end

	return ms
end -- of function



function notxt(txt,text)
if txt=="yes" then nt=text else nt="" end
return nt
end

function nomt(txt,text)
return if txt=="yes" then text else "" end
end
	
function system(cd)
--[[
variable -> argument for example fs_free
device --> system-device for example wlan0
del --> delimiter of number
tf --> format of shown time for example 01:15 uhr or 1:15 pm
se --> shown ending for example 1.000 instead of 1.000 mb
dt --> show current date
st --> display extra-text for example unmounted yes or no
txt --> show word for example 10 mb frei

you can call the function like this (example):
system({variable="totaldown",device="wlan0",del=',',se="no"})
]]--

local t=nil
local x=nil

local variable=cd.variable
local device=cd.device or ''
local del=cd.del or '.'
local tf=cd.tf or '24'
local se=cd.se or "yes"
local txt=cd.txt or "yes"
local dt=cd.dt or "no"
local st=cd.st or "yes"

rawdata=conky_parse("${"..variable..' '..device.."}")
adv=parse(rawdata,del,se)

	if string.find(variable,"cpu") ~= nil then
		ms=nounit(device,se,e6,rawdata).." "..notxt(txt,t2)
	elseif string.find(variable,"uptime") ~= nil or string.find(variable,"user_number") ~= nil then
		ms=rawdata
	elseif ((string.find(variable, "perc") ~= nil) or (string.find(variable, "percent") ~= nil)) then
	--------------------------------------------------------------------	
		if string.find(variable, "fs_free_perc") ~= nil then
		ms=conky_parse("${if_mounted "..device.."}"..nounit(device,se,e6,rawdata).." "..notxt(txt,t1).."${else}"..nomt(st,t3).."${endif}")
		elseif string.find(variable, "fs_used_perc") ~= nil then
		ms=conky_parse("${if_mounted "..device.."}"..nounit(device,se,e6,rawdata).." "..notxt(txt,t2).."${else}"..nomt(st,t3).."${endif}")
		elseif string.find(variable, "swapperc") ~= nil then
		ms=nounit(device,se,e6,rawdata).." "..notxt(txt,t1)
		elseif string.find(variable, "memperc") ~= nil then
		ms=nounit(device,se,e6,rawdata).." "..notxt(txt,t2)
		elseif string.find(variable, "battery_percent") ~= nil then
		ms=nounit(device,se,e6,rawdata).." "..notxt(txt,t6)
		else 
		ms=nounit(device,se,e6,rawdata) 
		end
	--------------------------------------------------------------------
	elseif ((string.find(variable,"freq") ~= nil) and (string.find(variable,"_g") == nil)) then
		jn=chgFormat(adv,del)
		ms=nounit(device,se,e7,jn)
	elseif ((string.find(variable,"freq") ~= nil) and (string.find(variable,"_g") ~= nil)) then
		jn=chgFormat(adv,del)
		ms=nounit(device,se,e8,add_decimal(jn,del))

	--------------------------------------------------------------------
	elseif string.find(variable, "swapmax") ~= nil then
	  ms=snu(txt,t5,adv)
	--------------------------------------------------------------------
	elseif string.find(variable,"loadavg") ~= nil then
		ms=rawdata
	--------------------------------------------------------------------
	elseif string.find(variable,"memfree") ~= nil or string.find(variable,"memeasyfree") ~= nil then
		ms=snu(txt,t1,adv)
	elseif string.find(variable,"swapfree") ~= nil then
		ms=snu(txt,t1,adv)

	elseif string.find(variable,"wireless_bitrate") ~= nil then
		t=rawdata:gsub("Mb/s","")
		t=chgDel(t,del)
		t=add_decimal(t,del)
		t=t:gsub(" ","") -- remove spaces
		ms=conky_parse("${if_up "..device.."}"..nounit(device,se,e9,t).."${else}"..t4.."${endif}")
	elseif string.find(variable,"wireless_essid") ~= nil or string.find(variable,"wireless_mode") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..rawdata.."${else}"..t4.."${endif}")
	elseif string.find(variable,"wireless_link_qual") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..nounit(device,se,e6,adv).."${else}"..t4.."${endif}")
	elseif string.find(variable,"upspeedf") ~= nil or string.find(variable,"downspeedf") ~= nil then
		jn=chgFormat(adv,del) -- chg format
		ms=conky_parse("${if_up "..device.."}"..nounit(device,se,e10,add_decimal(jn,del)).."${else}"..t4.."${endif}")
	elseif string.find(variable,"battery") ~= nil then
		ms=rawdata
	--------------------------------------------------------------------
	elseif string.find(variable,"up") == nil and string.find(variable,"time") ~= nil then

if dt=="yes" then
ms=nounit(device,se,"",adv)
ms=ms:gsub(" ","")
else

if tf == "24" then ms=nounit(device,se,e11,adv) elseif tf == "12" then ms=convert12(rawdata,tf) end 

end

--[[
%B name of the month
%m month number, for example 05
%y year short number, for example 13
%Y year long number, for example 2013
%d day number
]]--

	else
	--------------------------------------------------------------------
		if string.find(device,"wlan") ~= nil or string.find(device,"eth") ~= nil then
		ms=conky_parse("${if_up "..device.."}"..adv.."${else}"..t4.."${endif}")
		elseif string.find(device,"media") ~= nil then
		  --------------------------------------------------------------
          if txt=="no" and string.find(variable,"free") ~= nil then
           ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..nomt(st,t3).."${endif}")
          elseif txt=="yes" and string.find(variable,"free") ~= nil then
           ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t1.."${else}"..nomt(st,t3).."${endif}")

		  elseif txt=="no" and string.find(variable,"used") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..nomt(st,t3).."${endif}")
		  elseif txt=="yes" and string.find(variable,"used") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t2.."${else}"..nomt(st,t3).."${endif}")
		   
		  elseif txt=="no" and string.find(variable,"size") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.."${else}"..t3.."${endif}")
		  elseif txt=="yes" and string.find(variable,"size") ~= nil then
		   ms=conky_parse("${if_mounted "..device.."}"..adv.." "..t5.."${else}"..nomt(st,t3).."${endif}")
		   
		  end
		  --------------------------------------------------------------
		else ms=adv  end 
	--------------------------------------------------------------------
	end

	return ms
end -- of function

-- convert 24h-format into 12h-format, for example 16:00 -> 4:00 pm
function convert12(value,format) 

local stunden=nil
local minuten=nil
local zeit=nil
local sekunden=nil

local stunden=string.sub(value,1,2) 	-- hours
local stunden=tonumber(stunden) 		-- convert hours into numbers
local minuten=string.sub(value,4,5)	 	-- minutes
local sekunden=string.sub(value,7,8) 	-- seconds

-- still calculate if string doesn't exists
if not sekunden then sekunden=''; end

if stunden > 12 and stunden < 24 then
	if sekunden ~= '' then
	zeit=(stunden-12)..':'..minuten..':'..sekunden..' pm'
	elseif sekunden == '' then
	zeit=(stunden-12)..':'..minuten..' pm'
	end
elseif stunden < 12 then
	if sekunden ~= '' then
	zeit=stunden..':'..minuten..':'..sekunden..' am'
	elseif sekunden == '' then
	zeit=stunden..':'..minuten..' am'
	end
elseif stunden == 12 then
	if sekunden ~= '' then
	zeit=stunden..':'..minuten..':'..sekunden..' pm'
	elseif sekunden == '' then
	zeit=stunden..':'..minuten..' pm'
	end
elseif stunden == 24 or stunden == 0 then
	if sekunden ~= '' then
	zeit=(stunden-12)..':'..minuten..':'..sekunden..' am'
	elseif sekunden == '' then
	zeit=(stunden-12)..':'..minuten..' am'
	end
end

return zeit

end


function dropZero(wert) -- drop leading charcacter

local ausgabe=nil
local erstezahl=tonumber(string.sub(wert,1,1))

 if erstezahl == 0 then
 ausgabe=string.sub(wert,2,5)
 else
 ausgabe=string.sub(wert,1,5)
 end -- of if

return ausgabe

end -- of function


function draw_bar(db) -- draw simple bar
------------------------------------------------------------------------
local var=nil
local dev=nil
local width=nil
local height=nil
local across=nil
local down=nil
local bgc=nil
local bga=nil
local inc=nil
local ina=nil
local lc=nil
local la=nil
local lw=nil
local rotate=nil
local justify=nil
------------------------------------------------------------------------
var=db.var
m=db.max or 100
dev=db.dev or ""
width,height=db.w,db.h
across,down=db.x,db.y
bgc,inc,lc=db.bgc,db.indc,db.lc
------------------------------------------------------------------------
bga=db.bga or 1
ina=db.inda or 1
la=db.la or 1
------------------------------------------------------------------------
lw=db.lw
rotate=db.r or 0
justify=db.j or "l"
------------------------------------------------------------------------
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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
------------------------------------------------------------------------
if updates>5 then -- starts the display

--indicator calculation
if not dev then dev=''; end

conum=conky_parse("${"..var..' '..dev.."}")
conum=tonumber(conum)

local inum=(((width-lw)/100)*(conum or 0))
local x =  100 * inum / m

-- justify bar
if justify=="r" then across=across-width elseif justify=="l" then across=across end

-- background bar ------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_source_rgba (cr, col(bgc, bga));
cairo_rectangle (cr, 0, 0, (width-lw), (height-lw))
cairo_fill (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
--indicator bar --------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_source_rgba (cr, col(inc,ina));
cairo_rectangle (cr, 0, 0, x, (height-lw))
cairo_fill (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
--boundary line --------------------------------------------------------
cairo_translate (cr, (across+(lw/2)), (down+(lw/2))) 
cairo_rotate (cr, rotate*math.pi/180)
cairo_set_line_width (cr, lw);
cairo_set_source_rgba (cr, col(lc,la));
cairo_rectangle (cr, -lw/2, -lw/2, width, height)
cairo_stroke (cr)
cairo_rotate (cr, (rotate*-1)*math.pi/180)
cairo_translate (cr, -1*(across+(lw/2)), -1*(down+(lw/2))) 
	end
end

-- ################################################
-- ## umwandeln von zahlen in wörter ########################
-- ################################################

function n2w(number)
--by mrpeachy 11-4-2012
local n1_tab={}
local n2_tab={}
number=tonumber(number)
local n_len=string.len(number)
if number<0 then
number=tonumber(string.sub(number,2,n_len))
minus="minus "
else
number=number
minus=""
end
if number>99 then
h=tonumber(string.sub(number,1,1))
tu=tonumber(string.sub(number,2,3))
t=tonumber(string.sub(number,2,2))
u=tonumber(string.sub(number,3,3))
elseif number<100 then
tu=number
t=tonumber(string.sub(number,1,1))
u=tonumber(string.sub(number,2,2))
end
n1_tab={"eins","zwei","drei","vier","fünf","sechs","sieben","acht","neun","zehn","elf","zwölf","dreizehn","vierzehn","fünfzehn","sechzehn","siebzehn","achtzehn","neunzehn",}
n2_tab={"zehn","zwanzig","dreißig","vierzig","fünfzig","sechzig","siebzig","achtzig","neunzig"}
if number>0 then n0="" else n0="null" end
if tu<20 and tu~=10 and tu~=0 then 
	ausgabe=n1_tab[tu]
elseif tu==10 then
	ausgabe="zehn"
elseif tu==0 then
	ausgabe="null"
elseif tu>19 then
	if u>0 then 
	joinu=" " 
	u=n1_tab[u]
	else 
	joinu=""
	u=""
	end
	g=string.sub(number,2,2)
	ausgabe=international(tu,g,n2_tab[t])
--	out=n2_tab[t]..joinu..u -- original
end
if number>99 and number~=100 then
	h=n1_tab[h]
	return minus..h.." hundred and "..ausgabe
elseif number==100 then
	return "einhundert"
elseif number<100 then
	return minus..ausgabe
end
end--function

function international(lang,geschnitten,wort)
local nummer=nil
local kurzezahl=nil

local anzahl=tonumber(lang)
local kurzezahl=tonumber(geschnitten)

if kurzezahl==1 or anzahl==1 then

 if string.len(anzahl)>1  then
 nummer='einund'..n2_tab[t]     -- gives me for example 21, 31 etc
 elseif string.len(anzahl)==1 then
 nummer='eins'			        -- gives me the number 1
 end

elseif kurzezahl~=1 or anzahl ~=1 then

   if anzahl==0 then
   nummer=wort                                     -- should give me the word 'null' (zero)
   elseif tonumber(string.sub(anzahl,1,1)) and tonumber(string.sub(anzahl,2,2))==0 then   --
   nummer=wort                                     -- gives me numbers like 10,20,30 etc.
   else 
    nummer=n2w(kurzezahl)..'und'..wort         --  gives me such numbers like 22,23,24 etc.
    end

end

return nummer

end -- der fun ktion

-- #####################################################################
-- ## end of functions to modify conky-output ##########################
-- #####################################################################


-- #####################################################################
-- ## gimmicks #########################################################
-- #####################################################################

function get_image() -- grab url of the 'image of the day' by the nasa 
	local uri='http://www.nasa.gov/rss/image_of_the_day.rss' -- address of rss-file 
	local f = assert(io.popen('curl -s '..uri, 'r')) -- get content of the rss-file
	local s = assert(f:read('*a'))
	f:close()
	s, f = string.gsub(s, ".*image\/jpeg.*(http://.*\.jpg).*", "%1")
	return s
end


function potw_uri() --  grab url of the 'picture of the week' by hubble 
	local uri = 'http://feeds.feedburner.com/hubble_potw?format=xml'
	local f = assert(io.popen('curl -s '..uri, 'r'))
	local s = assert(f:read('*a'))
	f:close()
	local b = nil
	local e = nil
	b,e,s = string.find(s,'(http://www%.spacetelescope%.org/static/archives/images/news/potw%d-.%.jpg)')
	return(s)
end

function conky_battbar() -- display battery bar

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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
------------------------------------------------------------------------

out({x=conky_window.width,y=535,c=0xffff00,shaded="yes",fs=14,txt=system({variable="battery_percent",device="BAT1"}),hj="r"})

cairo_set_line_width (cr, 20); --set line thickness
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND)
x_position=45
y_position=530
length=80 --set total length of line
cairo_set_source_rgba (cr,1,1,1,0.5) --set color and alpha for background
cairo_move_to (cr,x_position,y_position)--reference positions set above
cairo_rel_line_to (cr,length,0)--reference length set above
cairo_stroke (cr)-- draws the line

--draw indicator line, draw after background so it draws ontop
battperc=tonumber(conky_parse("${battery_percent BAT1}"))--tonumber makes sure battvalue is a number
battvalue=(length/100)*battperc
cairo_set_source_rgba (cr,1,1,0,0.8)
cairo_move_to (cr,x_position,y_position)--reference positions set above
cairo_rel_line_to (cr,battvalue,0)--reference battvalue calculated above
cairo_stroke (cr)-- draws the line
------------------------------------------------------------------------
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end-- end main function

--END OF SCRIPT

do u have an idea what i could do?

Last edited by lionhead (2013-06-01 15:52:35)

Offline

#5473 2013-06-02 14:57:07

ichase
#! CrunchBanger
Registered: 2011-03-16
Posts: 146

Re: Conky v1.9 Thread

Hope everyone is doing well and enjoying the weekend.
Time has not let me mess with Conky for a bit.  sad  Sad state of affairs  LOL
Only running 4 conky's on this desktop setup for now, but more are waiting in the wings to be launched.  Hoping to get some time soon to start playing some more.  smile

5c8ba9257859156.jpg

Offline

#5474 2013-06-02 21:29:52

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky v1.9 Thread

ichase wrote:

Hope everyone is doing well and enjoying the weekend.
Time has not let me mess with Conky for a bit.  sad  Sad state of affairs  LOL
Only running 4 conky's on this desktop setup for now, but more are waiting in the wings to be launched.  Hoping to get some time soon to start playing some more.  smile

http://thumbnails104.imagebam.com/25786/5c8ba9257859156.jpg

Only 4?  But you have room there for at least another 6-pack.  big_smile


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

Be excellent to each other!

#5475 2013-06-03 19:35:53

folti
#! Member
Registered: 2013-05-26
Posts: 82

Re: Conky v1.9 Thread

http://img593.imageshack.us/img593/7519/screenshot0603201309300.png
hi:)

how to get rid off that "^A" between temp value and "°C"?


this is conkyrc entry:

${execpi 15 hddtemp /dev/sd[abcd]}

Last edited by folti (2013-06-03 19:42:56)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo