Originally Posted by
mrpeachy
Looks good....can't get it to run though....
Code:
Conky: llua_do_call: function conky_weather execution failed: attempt to call a nil value
All the paths seem to be correct.
/home/glen/v9000i/conky_weather
Code:
##############################################
# Settings
##############################################
max_specials 10000
max_user_text 1500000
background no
use_xft yes
#xftfont Sans:size=12
#xftalpha 1
font Mono:size=8
total_run_times 0
own_window yes
##own_window_argb_visual yes
own_window_transparent yes
own_window_type normal
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 450 650
maximum_width 370
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders yes
default_color white
default_shade_color black
default_outline_color white
alignment top_right
gap_x 10
gap_y 10
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale yes
color1 86acad #darker blue
color2 b1c9c9 #lighter blue
text_buffer_size 100000
top_name_width 10
update_interval 1
own_window_title interactiveconkyrc
lua_load ~/v9000i/v9001.lua
lua_draw_hook_post weather
lua_load ~/v9000i/iweather.lua
####################################################
## Set the path to button_script.lua here ##########
####################################################
lua_load ~/v9000i/button_script.lua
####################################################
## activate mouse click logging ####################
####################################################
lua_draw_hook_pre get_mouse {"interactiveconkyrc","/tmp/xdo"}
## after function call, table containing window title and path to click log file
## before running script create a blank log file first. In the example above "/tmp/xdo" credate a blank file called xdo in your /tmp directory
####################################################
## restart click logging on conkyrc save/startup ###
####################################################
lua_startup_hook start_xdo /tmp/xdo
## send click file location following function call if not set up in lua script
####################################################
## kill xdotool process on conkyrc save/shutdown ###
####################################################
lua_shutdown_hook stop_xdo
####################################################
TEXT
/home/glen/v9000i/iweather.lua
Code:
--DISPLAY FUNCTION--DISPLAY FUNCTION--DISPLAY FUNCTION--DISPLAY FUNCTION-
_G.weather_script = function()--#### DO NOT EDIT THIS LINE ##############
--#######################################################################
--these tables hold the coordinates for each repeat do not edit #########
top_left_x_coordinate={}--###############################################
top_left_y_coordinate={}--###############################################
--#######################################################################
--SET DEFAULTS ##########################################################
--set defaults do not localise these defaults if you use a seperate display script
default_font="URW Gothic L"--font must be in quotes
default_font_size=11
default_color=0xffffff--white
default_alpha=1--fully opaque
default_image_width=50
default_image_height=50
--END OF DEFAULTS #######################################################
--#######################################################################
--START OF BUTTON CODE -- START OF BUTTON CODE -- START OF BUTTON CODE
--########################################################################################
function button_settings()
dh=do_button({fs_off={"14"},fs_on={"14"},fxadj_off={10},fxadj_on={10},fyadj_off={-5},fyadj_on={-5},text=1,font_off={"URW Gothic L"},font_on={"URW Gothic L"},txt_on={"DAYS"},txt_off={"HOURS"},dolw_on=2,dolw_off=2,docol_off=0x000000,docol_on=0x000000,dtype_off=3,dfal_on=0.5,dfcol_on=0xffffff,dfal_off=0.5,btype=1,bname="dayhour",blx_off=296.5,bly_off=166+240,bw_off=70,bh_off=23,draw=1,on_on_on={"current"},on_on_off={"current"},off_on_off={"day1","day2","day3","day4","day5","day6","day7","day8","day9","day10"},off_on_on={"day1","day2","day3","day4","day5","day6","day7","day8","day9","day10"}})
local b1=do_button({dfal_off=0.5,btype=1,bname="day1",blx_off=9.5,bly_off=166,bw_off=70,bh_off=23,draw=1, off_on_on={"day2","day3","day4","day5","day6","day7","day8","day9","day10","current"}})
local b2=do_button({dfal_off=0.5,btype=1,bname="day2",blx_off=81.5,bly_off=166,bw_off=69.5,bh_off=23,draw=1, off_on_on={"day1","day3","day4","day5","day6","day7","day8","day9","day10","current"}})
local b3=do_button({dfal_off=0.5,btype=1,bname="day3",blx_off=153,bly_off=166,bw_off=70,bh_off=23,draw=1, off_on_on={"day1","day2","day4","day5","day6","day7","day8","day9","day10","current"}})
local b4=do_button({dfal_off=0.5,btype=1,bname="day4",blx_off=225,bly_off=166,bw_off=69.5,bh_off=23,draw=1, off_on_on={"day1","day2","day3","day5","day6","day7","day8","day9","day10","current"}})
local b5=do_button({dfal_off=0.5,btype=1,bname="day5",blx_off=296.5,bly_off=166,bw_off=70,bh_off=23,draw=1, off_on_on={"day1","day2","day3","day4","day6","day7","day8","day9","day10","current"}})
local b6=do_button({dfal_off=0.5,btype=1,bname="day6",blx_off=9.5,bly_off=166+120,bw_off=70,bh_off=23,draw=1, off_on_on={"day1","day2","day3","day4","day5","day7","day8","day9","day10","current"}})
local b7=do_button({dfal_off=0.5,btype=1,bname="day7",blx_off=81.5,bly_off=166+120,bw_off=69.5,bh_off=23,draw=1, off_on_on={"day1","day2","day3","day4","day5","day6","day8","day9","day10","current"}})
local b8=do_button({dfal_off=0.5,btype=1,bname="day8",blx_off=153,bly_off=166+120,bw_off=70,bh_off=23,draw=1, off_on_on={"day1","day2","day3","day4","day5","day6","day7","day9","day10","current"}})
local b9=do_button({dfal_off=0.5,btype=1,bname="day9",blx_off=225,bly_off=166+120,bw_off=69.5,bh_off=23,draw=1, off_on_on={"day1","day2","day3","day4","day5","day6","day7","day8","day10","current"}})
local b10=do_button({dfal_off=0.5,btype=1,bname="day10",blx_off=296.5,bly_off=166+120,bw_off=70,bh_off=23,draw=1, off_on_on={"day1","day2","day3","day4","day5","day6","day7","day8","day9","current"}})
local bc=do_button({dfal_off=0.5,st_type=1,btype=1,bname="current",blx_off=264,bly_off=134.5,bw_off=23,bh_off=98,draw=1, off_on_on={"day1","day2","day3","day4","day5","day6","day7","day8","day9","day10"}})
if b1==1 and b2==0 and b3==0 and b4==0 and b5==0 and b6==0 and b7==0 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=1
elseif b1==0 and b2==1 and b3==0 and b4==0 and b5==0 and b6==0 and b7==0 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=2
elseif b1==0 and b2==0 and b3==1 and b4==0 and b5==0 and b6==0 and b7==0 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=3
elseif b1==0 and b2==0 and b3==0 and b4==1 and b5==0 and b6==0 and b7==0 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=4
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==1 and b6==0 and b7==0 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=5
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==0 and b6==1 and b7==0 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=6
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==0 and b6==0 and b7==1 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=7
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==0 and b6==0 and b7==0 and b8==1 and b9==0 and b10==0 and bc==0 then
showday=8
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==0 and b6==0 and b7==0 and b8==0 and b9==1 and b10==0 and bc==0 then
showday=9
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==0 and b6==0 and b7==0 and b8==0 and b9==0 and b10==1 and bc==0 then
showday=10
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==0 and b6==0 and b7==0 and b8==0 and b9==0 and b10==0 and bc==1 then
showday=11
elseif b1==0 and b2==0 and b3==0 and b4==0 and b5==0 and b6==0 and b7==0 and b8==0 and b9==0 and b10==0 and bc==0 then
showday=0
end
end--function button_settings
--########################################################################################
--END OF BUTTON CODE ----END OF BUTTON CODE ----END OF BUTTON CODE ---
--#######################################################################
image({x=0,y=0,w=376,h=265*(620/421),file="/home/glen/v9000i/additional_files/v9000i10day.png"})
--START OF WEATHER CODE -- START OF WEATHER CODE -- START OF WEATHER CODE
out({a=1,fs=10,x=12,y=20,txt=weather_location.." "..now["month_num"].."/"..now["date"].."/"..now["year"].." @"..now["time_24"]})
out({a=1,fs=16,x=280,y=25,txt=os.date("%I:%m %p")})
ct={"C","U","R","R","E","N","T"}
for i=1,7 do
out({hj="c",a=1,fs=14,x=274,y=50+(13*(i-1)),txt=ct[i]})
end
--current window
image({x=300,y=45,h=50,w=50,file=now["weather_icon"]})
out({a=1,fs=32,x=310,y=125,txt=now["temp"].."°"})
--DATA WINDOW
if showday==nil then showday=11 end
if dh==0 then
if showday>0 and showday<11 then
out({a=1,fs=14,x=15,y=48,txt=forecast_day[tonumber(showday)].." "..forecast_month[tonumber(showday)].." "..forecast_date[tonumber(showday)]})
out({a=1,fs=18,x=15,y=65,txt=conditions[tonumber(showday)]})
gap=13
ypos=67+gap
out({a=1,fs=12,x=15,y=ypos,txt="High: "..high_temp[tonumber(showday)].."°"})
out({a=1,fs=12,x=90,y=ypos,txt="Low: "..low_temp[tonumber(showday)].."°"})
out({a=1,fs=12,x=165,y=ypos,txt="Hum: "..humidity[tonumber(showday)].."%"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Cloud: "..cloud_cover[tonumber(showday)].."%"})
out({a=1,fs=12,x=90,y=ypos,txt="Rain: "..precipitation[tonumber(showday)].."%"})
out({a=1,fs=12,x=165,y=ypos,txt="Snow: "..snow[tonumber(showday)].."%"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Sun: "..sun_rise_24[tonumber(showday)].."/"..sun_set_24[tonumber(showday)]})
out({a=1,fs=12,x=140,y=ypos,txt="UV: "..uv_index_num[tonumber(showday)].."/"..uv_index_txt[tonumber(showday)]})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Moon: "..moon_rise_24[tonumber(showday)].."/"..moon_set_24[tonumber(showday)]})
out({a=1,fs=12,x=140,y=ypos,txt=moon_phase[tonumber(showday)]})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Wind: "..wind_mph[tonumber(showday)].."mph"})
out({a=1,fs=12,x=115,y=ypos,txt=wind_deg[tonumber(showday)].."°"})
out({a=1,fs=12,x=165,y=ypos,txt=wind_nesw[tonumber(showday)]})
elseif showday==11 then
out({a=1,fs=14,x=15,y=48,txt=now["day"].." "..now["month"].." "..now["date"]})
out({a=1,fs=18,x=15,y=65,txt=now["conditions"]})
gap=13
ypos=67+gap
out({a=1,fs=12,x=15,y=ypos,txt="Temp: "..now["temp"].."°"})
out({a=1,fs=12,x=100,y=ypos,txt="Feels: "..now["feels_like"].."°"})
out({a=1,fs=12,x=165,y=ypos,txt="Hum: "..now["humidity"].."°"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Chill: "..now["wind_chill"].."°"})
out({a=1,fs=12,x=100,y=ypos,txt="Heat: "..now["heat_index"].."°"})
out({a=1,fs=12,x=165,y=ypos,txt="Dew: "..now["dew_point"].."°"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Ceil: "..now["ceiling"]})
out({a=1,fs=12,x=100,y=ypos,txt="Vis: "..now["visibility"]})
out({a=1,fs=12,x=165,y=ypos,txt="Pressure: "..now["pressure"].."\""})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Wind: "..now["wind_mph"]})
out({a=1,fs=12,x=115,y=ypos,txt=now["wind_deg"].."°"})
out({a=1,fs=12,x=165,y=ypos,txt=now["wind_nesw"]})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Gusts: "..now["wind_gusts_km"]})
elseif showday==0 then
out({a=1,fs=18,x=15,y=50,txt=""})
end
elseif dh==1 then
if showday>0 and showday<11 then
out({a=1,fs=14,x=15,y=48,txt=forecast_hour[tonumber(showday)].." "..hour_day_txt[tonumber(showday)].." "..hour_month_txt[tonumber(showday)].." "..hour_day_num[tonumber(showday)]})
out({a=1,fs=18,x=15,y=65,txt=conditions[tonumber(showday)]})
gap=13
ypos=67+gap
out({a=1,fs=12,x=15,y=ypos,txt="Temp: "..hour_temp[tonumber(showday)].."°"})
out({a=1,fs=12,x=90,y=ypos,txt="Chill: "..hour_windchill[tonumber(showday)].."°"})
out({a=1,fs=12,x=165,y=ypos,txt="Heat: "..hour_heatindex[tonumber(showday)].."°"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Dew: "..hour_dewpoint[tonumber(showday)].."°"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Cloud: "..hour_clouds[tonumber(showday)].."%"})
out({a=1,fs=12,x=90,y=ypos,txt="Rain: "..hour_precipitation[tonumber(showday)].."%"})
out({a=1,fs=12,x=165,y=ypos,txt="Snow: "..hour_snow[tonumber(showday)].."%"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Visibility: "..hour_visibility_mi[tonumber(showday)]})
out({a=1,fs=12,x=130,y=ypos,txt="UV: "..hour_uvindex_num[tonumber(showday)].."/"..hour_uvindex_txt[tonumber(showday)]})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Wind: "..hour_wind_mph[tonumber(showday)]})
out({a=1,fs=12,x=130,y=ypos,txt=hour_wind_nsew[tonumber(showday)]})
--out({a=1,fs=12,x=165,y=ypos,txt=wind_nesw[tonumber(showday)]})
elseif showday==11 then
out({a=1,fs=14,x=15,y=48,txt=now["day"].." "..now["month"].." "..now["date"]})
out({a=1,fs=18,x=15,y=65,txt=now["conditions"]})
gap=13
ypos=67+gap
out({a=1,fs=12,x=15,y=ypos,txt="Temp: "..now["temp"].."°"})
out({a=1,fs=12,x=100,y=ypos,txt="Feels: "..now["feels_like"].."°"})
out({a=1,fs=12,x=165,y=ypos,txt="Hum: "..now["humidity"].."°"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Chill: "..now["wind_chill"].."°"})
out({a=1,fs=12,x=100,y=ypos,txt="Heat: "..now["heat_index"].."°"})
out({a=1,fs=12,x=165,y=ypos,txt="Dew: "..now["dew_point"].."°"})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Ceil: "..now["ceiling"]})
out({a=1,fs=12,x=100,y=ypos,txt="Vis: "..now["visibility"]})
out({a=1,fs=12,x=165,y=ypos,txt="Pressure: "..now["pressure"].."\""})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Wind: "..now["wind_mph"]})
out({a=1,fs=12,x=115,y=ypos,txt=now["wind_deg"].."°"})
out({a=1,fs=12,x=165,y=ypos,txt=now["wind_nesw"]})
ypos=ypos+gap
out({a=1,fs=12,x=15,y=ypos,txt="Gusts: "..now["wind_gusts_km"]})
elseif showday==0 then
out({a=1,fs=18,x=15,y=50,txt=""})
end
end
--FORECAST DAY BOXES
--set start forecast day
start_day=1
--set total forecast days you want to display
number_of_days=5
topx=20
py=160
--set coordinates for top lef corners for each repeat
top_left_x_coordinate[1],top_left_y_coordinate[1] =topx ,py
top_left_x_coordinate[2],top_left_y_coordinate[2] =topx+70 ,py
top_left_x_coordinate[3],top_left_y_coordinate[3] =topx+70+71.5 ,py
top_left_x_coordinate[4],top_left_y_coordinate[4] =topx+70+72+71.5 ,py
top_left_x_coordinate[5],top_left_y_coordinate[5] =topx+70+72+71.5+71.5 ,py
top_left_x_coordinate[6],top_left_y_coordinate[6] =topx+70+72+71.5+71.5+71.5 ,py
if dh==0 then
--########################################################################################
for i=start_day,number_of_days do --start of day repeat, do not edit #######
tlx=top_left_x_coordinate[i] --sets top left x position for each repeat ##################
tly=top_left_y_coordinate[i] --sets top left y position for each repeat ##################
--########################################################################################
--top row
out({a=1,fs=12,x=tlx-4,y=tly,txt=forecast_day_short[i].." "..forecast_month_num[i].."/"..forecast_date[i]})
image({x=tlx,y=tly+10,h=45,w=45,file=weather_icon[i]})
out({a=1,fs=12,x=tlx,y=tly+91,txt=high_temp[i].."°"})
out({a=1,fs=12,x=tlx+35,y=tly+91,txt=low_temp[i].."°"})
out({a=1,fs=14,x=tlx+5,y=tly+73,txt=precipitation[i].."%"})
tly=tly+120
--bottom row
out({a=1,fs=12,x=tlx-4,y=tly,txt=forecast_day_short[i+5].." "..forecast_month_num[i+5].."/"..forecast_date[i+5]})
image({x=tlx,y=tly+10,h=45,w=45,file=weather_icon[i+5]})
out({a=1,fs=12,x=tlx,y=tly+91,txt=high_temp[i+5].."°"})
out({a=1,fs=12,x=tlx+35,y=tly+91,txt=low_temp[i+5].."°"})
out({a=1,fs=14,x=tlx+5,y=tly+73,txt=precipitation[i+5].."%"})
--########################################################################################
end--of forecast repeat section ##########################################################
elseif dh==1 then
--########################################################################################
for i=start_day,number_of_days do --start of day repeat, do not edit #######
tlx=top_left_x_coordinate[i] --sets top left x position for each repeat ##################
tly=top_left_y_coordinate[i] --sets top left y position for each repeat ##################
--########################################################################################
--top row
out({a=1,fs=11,x=tlx-4,y=tly,txt=forecast_hour[i].." "..hour_month_num[i].."/"..hour_day_num[i]})
image({x=tlx,y=tly+10,h=45,w=45,file=hour_weather_icon[i]})
out({a=1,fs=12,x=tlx,y=tly+91,txt=hour_heatindex[i].."°"})
out({a=1,fs=12,x=tlx+35,y=tly+91,txt=hour_windchill[i].."°"})
out({a=1,fs=14,x=tlx+5,y=tly+73,txt=hour_precipitation[i].."%"})
tly=tly+120
--bottom row
out({a=1,fs=11,x=tlx-4,y=tly,txt=forecast_hour[i+5].." "..hour_month_num[i+5].."/"..hour_day_num[i+5]})
image({x=tlx,y=tly+10,h=45,w=45,file=hour_weather_icon[i+5]})
out({a=1,fs=12,x=tlx,y=tly+91,txt=hour_heatindex[i+5].."°"})
out({a=1,fs=12,x=tlx+35,y=tly+91,txt=hour_windchill[i+5].."°"})
out({a=1,fs=14,x=tlx+5,y=tly+73,txt=hour_precipitation[i+5].."%"})
--########################################################################################
end--of forecast repeat section ##########################################################
end--if dh
--########################################################################################
--END OF WEATHER CODE ----END OF WEATHER CODE ----END OF WEATHER CODE ---
--########################################################################################
end--of weather_display function do not edit this line ##################
--#######################################################################
/home/glen/v9000i/button_script.lua
Code:
--[[buttons by mrpeachy - thanks to barrybarrykelly for the xdotool method, gmonti for finding the deb files for the xdotool and arclance for xdotool error catching
see here for instructions: http://crunchbanglinux.org/forums/post/245759/#p245759
paste into conkyrc
####################################################
## Set the path to button_script.lua here ##########
####################################################
lua_load /home/mcdowall/conky/luai/button_script.lua
####################################################
## activate mouse click logging ####################
####################################################
lua_draw_hook_pre get_mouse {"interactiveconkyrc","/tmp/xdo"}
## after function call, table containing window title and path to click log file
## before running script create a blank log file first. In the example above "/tmp/xdo" credate a blank file called xdo in your /tmp directory
####################################################
## restart click logging on conkyrc save/startup ###
####################################################
lua_startup_hook start_xdo /tmp/xdo
## send click file location following function call if not set up in lua script
####################################################
## kill xdotool process on conkyrc save/shutdown ###
####################################################
lua_shutdown_hook stop_xdo
####################################################
]]
conky_name="interactiveconkyrc"
click_data_file ="/tmp/xdo"
--setup buttons here
function button_settings()
end--function button_settings
require 'cairo'
require 'imlib2'
function conky_start_xdo(rc_info)--######################################################################################################################
click_data_file=rc_info or click_data_file
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
os.execute("xdotool search --sync --classname 'conky' behave %@ mouse-click getmouselocation 2> /dev/null >> "..click_data_file.." &")
rc_info=nil
end--of function ##################################################################################################################################
function conky_stop_xdo()--######################################################################################################################
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
end--of function ##################################################################################################################################
buttons={}--######################################################################################################################################
click_table={}--##################################################################################################################################
start=1
function conky_get_mouse(rc_info)--###############################################################################################################
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)
--##########################################################################
if rc_info~=nil then
rc_info=loadstring("return" .. rc_info)()
end
--start click logging and calculations #####################################
--##########################################################################
if start==1 then
current_update=tonumber(conky_parse("${updates}"))
start=0
end
local updates=tonumber(conky_parse("${updates}"))
if updates==(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
local conky_name=rc_info[1] or conky_name
print ("own_window_title="..conky_name)
local f=io.popen("xwininfo -all -int -tree -name '"..conky_name.."'")
windata = f:read("*a")
f:close()
local windata=string.lower(windata)
local s,f,x=string.find(windata,"absolute%supper%pleft%sx%p%s*(%p*%d*)")
local s,f,y=string.find(windata,"absolute%supper%pleft%sy%p%s*(%p*%d*)")
local s,f,p=string.find(windata,"parent%swindow%sid%p%s(%d*)%s")
local s,f,w=string.find(windata,"xwininfo%p%swindow%sid%p%s(%d*)%s")
xwin={x,y,p,w,click_data_file}--don't blank with nil
print (xwin[1],xwin[2],xwin[3],xwin[4],xwin[5])
elseif updates<(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
xwin={0,0,0,0,click_data_file}
end--if updates== ###########################################################
--click calculations ########################################################
--get now location and window id ############################################
local f = io.popen("xdotool getmouselocation 2> /dev/null")
mousenow=(f:read())
f:close()
local mousenow=string.lower(mousenow or "x:0 y:0 window:0 ")
local s,f,mousenowx=string.find(mousenow,"x%p(%d*)%s")
local s,f,mousenowy=string.find(mousenow,"y%p(%d*)%s")
local s,f,xwinid=string.find(mousenow,"window%p(%d*)")
local localnowx=(tonumber(mousenowx) or 0)-xwin[1]
local localnowy=(tonumber(mousenowy) or 0)-xwin[2]
--read file if windowid matches
if tonumber(xwin[3])==tonumber(xwinid) or tonumber(xwin[4])==tonumber(xwinid) then
local f = io.open(xwin[5])
click = f:read()
f:close()
--get click location
if click==nil then click="x:0 y:0 window:0 " else print (click) end
local s,f,mousex=string.find(click,"x%p(%d*)%s")
local s,f,mousey=string.find(click,"y%p(%d*)%s")
local localx=(tonumber(mousex) or 0)-xwin[1]
local localy=(tonumber(mousey) or 0)-xwin[2]
click_table[1]=localx
click_table[2]=localy
click_table[3]=localnowx
click_table[4]=localnowy
click=nil
--blank file
local f = io.open(xwin[5],"w")
f:write("")
f:close()
else
click_table[1]=0
click_table[2]=0
click_table[3]=0
click_table[4]=0
end--window id matching
button_settings()
mousenow=nil
windata=nil
rc_info=nil
f=nil
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end-- end getmouse function ######################################################################################################################
--################################################################################################################################################
function do_button(bd)
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)
if bd.btype==nil then
bd=loadstring("return" .. bd)()
end
local localx=click_table[1] or 0
local localy=click_table[2] or 0
local localnowx=click_table[3] or 0
local localnowy=click_table[4] or 0
local button_name=bd.bname
local st_type=bd.st_type or 0
local btype=bd.btype or 1
local on_on_on=bd.on_on_on or {}
local on_on_off=bd.on_on_off or {}
local off_on_on=bd.off_on_on or {}
local off_on_off=bd.off_on_off or {}
local return_co=bd.return_co or 0
--#####################################
--#####################################
--initialize button
if buttons[tostring(button_name)]==nil then
if btype~=4 and st_type==0 then --button is off on start
buttons[tostring(button_name)]=0
elseif btype~=4 and st_type==1 then --button is on on start
buttons[tostring(button_name)]=1
elseif btype==4 then
buttons[tostring(button_name)]=1
end
end
--set mouse point type
if btype==1 or btype==3 or btype==4 then
--on off execute or cycle
localx=localx
localy=localy
elseif btype==2 then
--mouse over
localx=localnowx
localy=localnowy
else
print ("button type not set")
end
--set click area if on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
--button is off
blx=bd.blx_off
bly=bd.bly_off
bw=bd.bw_off
bh=bd.bh_off
elseif btype~=4 and buttons[tostring(button_name)]==1 then
--button is on
blx=bd.blx_on or bd.blx_off
bly=bd.bly_on or bd.bly_off
bw=bd.bw_on or bd.bw_off
bh=bd.bh_on or bd.bh_off
elseif btype==4 then
local blxt=bd.blx_cyc
local blyt=bd.bly_cyc
local bwt=bd.bw_cyc
local bht=bd.bh_cyc
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
blx=blxt[set] or blxt[#blxt]
bly=blyt[set] or blyt[#blyt]
bw=bwt[set] or bwt[#bwt]
bh=bht[set] or bht[#bht]
end
--set mechanism based on button type
if btype==1 then --on off ##############################################################
--if click is inside box and button is not on - turn on
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
--turn on other buttons as set
for i=1,#on_on_on do
buttons[tostring(on_on_on[i])]=1
end
--turn off other buttons as set
for i=1,#off_on_on do
buttons[tostring(off_on_on[i])]=0
end
--if click is inside box and button is on - turn off
elseif localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
--turn off other buttons as set
for i=1,#off_on_off do
buttons[tostring(off_on_off[i])]=0
end
--turn on other buttons as set
for i=1,#on_on_off do
buttons[tostring(on_on_off[i])]=1
end
end
end --if btype==1###################################################################
if btype==2 then --mouse over ##############################################################
--if mouse is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
for i=1,#on_on_on do
buttons[tostring(on_on_on[i])]=1
end
--turn off other buttons as set
for i=1,#off_on_on do
buttons[tostring(off_on_on[i])]=0
end
--if click is inside box and button is on - turn off
else --mouse is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
for i=1,#off_on_off do
buttons[tostring(off_on_off[i])]=0
end
--turn on other buttons as set
for i=1,#on_on_off do
buttons[tostring(on_on_off[i])]=1
end
end --if mouse inside
end --if btype==3###################################################################
if btype==3 then --execte ##############################################################
--if mouse click is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
for i=1,#on_on_on do
buttons[tostring(on_on_on[i])]=1
end
--turn off other buttons as set
for i=1,#off_on_on do
buttons[tostring(off_on_on[i])]=0
end
--if click is inside box and button is on - turn off
else --mouse click is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
for i=1,#off_on_off do
buttons[tostring(off_on_off[i])]=0
end
--turn on other buttons as set
for i=1,#on_on_off do
buttons[tostring(on_on_off[i])]=1
end
end--if click inside
end --if btype==3###################################################################
if btype==4 then --cycle ##############################################################
local cynum=bd.cynum
--if mouse click is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
if buttons[tostring(button_name)]+1>cynum then
buttons[tostring(button_name)]=1
else
buttons[tostring(button_name)]=buttons[tostring(button_name)]+1
end
end--if click inside
end --if btype==4###################################################################
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
--draw #############################################################################
local draw=bd.draw or 0
if draw==1 then--#########################################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
dtype=bd.dtype_off or 1
--fill when off
dfblx=bd.dfxadj_off or 0
dfbly=bd.dfyadj_off or 0
dfw=bd.dfw_off or bw
dfh=bd.dfh_off or bh
dfcr=bd.dfcr_off or 0
dfcol=bd.dfcol_off or 0xffffff
dfal=bd.dfal_off or 1
--outline when off
doblx=bd.doxadj_off or 0
dobly=bd.doyadj_off or 0
dow=bd.dow_off or bw
doh=bd.doh_off or bh
docr=bd.docr_off or 0
docol=bd.docol_off or 0xffffff
doal=bd.doal_off or 1
dolw=bd.dolw_off or 1
elseif btype~=4 and buttons[tostring(button_name)]==1 then--draw on and button on
dtype=bd.dtype_on or bd.dtype_off or 1
--fill when on
dfblx=bd.dfxadj_on or 0
dfbly=bd.dfyadj_on or 0
dfw=bd.dfw_on or bw
dfh=bd.dfh_on or bh
dfcr=bd.dfcr_on or 0
dfcol=bd.dfcol_on or 0xff0000
dfal=bd.dfal_on or 1
--outline when on
doblx=bd.doxadj_on or 0
dobly=bd.doyadj_on or 0
dow=bd.dow_on or bw
doh=bd.doh_on or bh
docr=bd.docr_on or 0
docol=bd.docol_on or 0xff0000
doal=bd.doal_on or 1
dolw=bd.dolw_on or 1
--###########################################
elseif btype==4 then --#######################
--###########################################
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
--set draw type
dtypet=bd.dtype_cyc or {1}
dtype=dtypet[set] or dtypet[#dtypet]
--fill cycle
local dfblxt=bd.dfxadj_cyc or {0}
local dfblyt=bd.dfyadj_cyc or {0}
local dfwt=bd.dfw_cyc or {bw}
local dfht=bd.dfh_cyc or {bh}
local dfcrt=bd.dfcr_cyc or {0}
local dfcolt=bd.dfcol_cyc or {0xffffff}
local dfalt=bd.dfal_cyc or {1}
dfblx=dfblxt[set] or dfblxt[#dfblxt] or 0
dfbly=dfblyt[set] or dfblyt[#dfblyt] or 0
dfw=dfwt[set] or dfwt[#dfwt] or bw
dfh=dfht[set] or dfht[#dfht] or bh
dfcr=dfcrt[set] or dfcrt[#dfcrt] or 0
dfcol=dfcolt[set] or dfcolt[#dfcolt] or 0xffffff
dfal=dfalt[set] or dfalt[#dfalt] or 1
--outline cycle
local doblxt=bd.doxadj_off or {0}
local doblyt=bd.doyadj_off or {0}
local dowt=bd.dow_off or {bw}
local doht=bd.doh_off or {bh}
local docrt=bd.docr_off or {0}
local docolt=bd.docol_off or {0xffffff}
local doalt=bd.doal_off or {1}
local dolwt=bd.dolw_off or {1}
doblx=doblxt[set] or doblxt[#doblxt] or 0
dobly=doblyt[set] or doblyt[#doblyt] or 0
dow=dowt[set] or dowt[#dowt] or bw
doh=doht[set] or doht[#doht] or bh
docr=docrt[set] or docrt[#docrt] or 0
docol=docolt[set] or docolt[#docolt] or 0xff0000
doal=doalt[set] or doalt[#doalt] or 1
dolw=dolwt[set] or dolwt[#dolwt] or 1
else
print ("error4")
end--check btype and button on off
--##########################
--draw based on type
if dtype==1 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
elseif dtype==2 then
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
elseif dtype==3 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
end
end--if draw=1 #################################################################################
local image=bd.image or 0
if image==1 then--##############################################################################
if btype~=4 and buttons[tostring(button_name)]==0 then
file=tostring(bd.im_file_off)
if file==nil then print("set image file") end
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
if tonumber(bw)==0 then
width=imlib_image_get_width()
end
if tonumber(bh)==0 then
height=imlib_image_get_height()
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype~=4 and buttons[tostring(button_name)]==1 then
file=tostring(bd.im_file_on)
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
if tonumber(bw)==0 then
width=imlib_image_get_width()
end
if tonumber(bh)==0 then
height=imlib_image_get_height()
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype==4 then
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local file=bd.im_file_cyc or {}
file=file[set]
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
if tonumber(bw)==0 then
width=imlib_image_get_width()
end
if tonumber(bh)==0 then
height=imlib_image_get_height()
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
end--btype test
end--if image ##################################################################################
local text=bd.text
if text==1 then --##############################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
local txt=bd.txt_off or {"text"}
local font=bd.font_off or {"mono"}
local fs=bd.fs_off or {12}
local fx=bd.fxadj_off or {0}
local fy=bd.fyadj_off or {0}
local fcol=bd.fcol_off or {0x000000}
local fal=bd.fal_off or {1}
for i=1,#txt do
cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs[i] or fs[#fs])
cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
cairo_show_text (cr, txt[i] or txt[#txt])
cairo_stroke (cr)
end
elseif btype~=4 and buttons[tostring(button_name)]==1 then
local txt=bd.txt_on or bd.txt_off or {"text"}
local font=bd.font_on or bd.font_off or {"mono"}
local fs=bd.fs_on or bd.fs_off or {12}
local fx=bd.fxadj_on or bd.fxadj_off or {0}
local fy=bd.fyadj_on or bd.fyadj_off or {0}
local fcol=bd.fcol_on or bd.fcol_off or {0x000000}
local fal=bd.fal_on or bd.fal_off or {1}
for i=1,#txt do
cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs[i] or fs[#fs])
cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
cairo_show_text (cr, txt[i] or txt[#txt])
cairo_stroke (cr)
end
elseif btype==4 then
--text for cycle trype button
--into tables round 1
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local txtt=bd.txt_cyc or {{"text"}}
local fontt=bd.font_cyc or {{"mono"}}
local fst=bd.fs_cyc or {{12}}
local fxt=bd.fxadj_cyc or {{0}}
local fyt=bd.fyadj_cyc or {{0}}
local fcolt=bd.fcol_cyc or {{0x000000}}
local falt=bd.fal_cyc or {{1}}
--into tables round 2
local txt=txtt[set] or txtt[#txtt]
local font=fontt[set] or fontt[#fontt]
local fs=fst[set] or fst[#fst]
local fx=fxt[set] or fxt[#fxt]
local fy=fyt[set] or fyt[#fyt]
local fcol=fcolt[set] or fcolt[#fcolt]
local fal=falt[set] or falt[#falt]
for i=1,#txt do
cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs[i] or fs[#fs])
cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
cairo_show_text (cr, txt[i] or txt[#txt])
cairo_stroke (cr)
end
else
print ("error with text")
end--if buttons[]==0
end--if text==1 ################################################################################
--##############################################################################################
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
if return_co==0 then
return tonumber(buttons[tostring(button_name)])
elseif return_co==1 then
return tonumber(buttons[tostring(button_name)]),localnowx,localnowy
end--return settings
end-- end button calculations function #################################
--######################################################################
function conky_rc_button(bd)--function to setup button in conkyrc
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
--###################################
send=do_button(bd)
--###################################
end--if updates>3
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return send or 0
end-- end main function
/home/glen/.v9000_config.lua
Code:
--SETTINGS AND PREFERENCES--SETTINGS AND PREFERENCES--SETTINGS AND PREFERENCES
function weather_settings()--#### DO NOT EDIT THIS LINE #################
--#######################################################################
--[[set update interval. update interval is based on conky cycles
if your conkyrc has an update_interval of 1, ie updates every second
then if you enter 60 below, the script will update every 60 seconds
however, if your conkyrc update_interval is 10, then by setting 60 below,
v9000 will update every 600 seconds (10 minutes)]]
general_settings={--opens settings table, all lines within table must end with a comma
update_interval=1800, --avoid an interval of 1
--get web address by going to the intellicast site and entering your location in the box
--click on "Extended Forecast" to get the necessary address
location="ASXX0089",--"ARBA0009"
units="C",--set "F" or "C"
tries=3,--this is the number of attempts the script will make with curl to download the data
--set location of weather images (replace "benjamin" with your own username)
weathericons="/home/glen/v9000i/additional_files/weathericons/",
--short conditions setup
--this section allows you to set your own shorter terms to replace the terms foud in conditions
--to use for current: now["conditions_short"], now["conditions_short_caps"], now["conditions_short_lc"]
--to use for forecast: conditions_short[n], conditions_short_caps[n], conditions_short_lc[n]
--ALSO USE THIS TABLE TO ENTER CONDITIONS TRANSLATIONS
con_short={--start of table, put entries below in form eg: ["Thunderstorm"]="T.Strm",
["Wind Early"]="Wnd AM",
["Snow Showers"]="Sn Shws",
["Thunderstorm"]="T.Strm",--remember to put a comma at the end of every entry
["Scattered"]="Scat",
["Few Showers"]="Fw Shws",
["Rain"]="rn",
["Showers"]="Shws",
},--this bracket closes the conditions table
--the script is capable of converting between several unit types
--set how many decimal places you want the conversions to show
decimal_places=1,
--some weather data options need to come with their own units attached as they can be NA on occasion
--set here what you want to have for units, or set "" for nothing
--include spaces, if desired, for formatting purposes.
--NOTE ALSO EDIT THESE SETTINGS FOR TRANSLATION PURPOSES
visibility_unit=" mi",
wind_mph_unit=" mph",
wind_km_unit=" kmh",
wind_kts_unit=" kts",
ceiling_unit=" ft",
wind_degrees_unit="°",
--set alerts on or off, set to 0 so that the script does not check for alerts
--set 1 to check for alerts
alert_check=1,
gethour=1,
}--closes general_settings table, do not edit
--END OF GENERAL SETTINGS
--#######################################################################
--do you want the script to use translation tables?
--set 1 if you want to translate, 0 if not.
--the translation tables are located below
translate=0--this settings is outside the tables
--TRANSLATION TABLES, activate by setting translate=1 above
--use con_short table above to translate weather conditions
--edit units settings above to complete translation
translation_tables={--opens table, do not edit
--translate NESW text
neswtext={--opens table, no comma here
S="t_S",
SSW="tsetSSW",
SW="t_SW",
WSW="t_WSW",
W="t_W",
WNW="t_WNW",
NW="t_NW",
NNW="t_NNW",
N="t_N",
NNE="t_NNE",
NE="t_NE",
ENE="t_ENE",
E="t_E",
ESE="t_ESE",
SE="t_SE",
SSE="t_SSE",
},--end of N E S W text table
--translate time suffix
tsuffix={--opens table, no comma here
AM="t_AM",
PM="t_PM",
},--end of time suffix table
--enter translations for uv index text
uvindextext={--opens table, no comma here
["Low"]="t_Low",
["Moderate"]="t_Moderate",
["High"]="t_High",
["Very High"]="t_Very High",--format is different because of the space in the text
["Extreme"]="t_Extreme",
},--end of uv text table
--enter translations for moonpahse
moonphases={--opens table, no comma here
["New"]="t_New",
["Full"]="t_Full",
["First Quarter"]="t_First Quarter",
["Last Quarter"]="t_Last Quarter",
["Waning Gibbous"]="t_Waning Gibbous",
["Waning Crescent"]="t_Waning Crescent",
["Waxing Crescent"]="t_Waxing Crescent",
["Waxing Gibbous"]="t_Waxing Gibbous",
},--end of moon phase table
--enter translations for FULL day names
daynames={--opens table, no comma here
Monday="t_Monday",
Tuesday="t_Tuesday",
Wednesday="t_Wednesday",
Thursday="t_Thursday",
Friday="t_Friday",
Saturday="t_Saturday",
Sunday="t_Sunday",
},--end day names table
--enter translations for SHORT day names
dayshort={--opens table, no comma here
Monday="t_Mon",
Tuesday="t_Tue",
Wednesday="t_Wed",
Thursday="t_Thu",
Friday="t_Fri",
Saturday="t_Sat",
Sunday="t_Sun",
},--end short day names table
--enter translation for FULL month names
monthnames={--opens table, no comma here
January="t_January",
February="t_February",
March="t_March",
April="t_April",
May="t_May",
June="t_June",
July="t_July",
August="t_August",
September="t_September",
October="t_October",
November="t_November",
December="t_December",
},--end of month name translations
--enter translations for SHORT month names
monthshort={--opens table, no comma here
January="t_Jan",
February="t_Feb",
March="t_Mar",
April="t_Apr",
May="t_May",
June="t_Jun",
July="t_Jul",
August="t_Aug",
September="t_Sep",
October="t_Oct",
November="t_Nov",
December="t_Dec",
},--end of short month name translations
--enter some additional translations
additional={--opens table, no comma here
NA="t_NA",
Unl="t_Unl",--for ceiling data option
},--end of additional translations
--END OF TRANSLATION TABLES
}--end of translation tables, do not edit
--#######################################################################
--NOTE if you make changes to these settings, they will only take effect at the next weather update
--or after killall conky and restart
--#######################################################################
if translate==0 then
return general_settings,0,0
elseif translate==1 then
return general_settings,translation_tables,1
end
end--OF SETTINGS AND PREFERENCES ########################################
--#######################################################################
/home/glen/v9000i/v9001.lua
Code:
--weather v9000 by mrpeachy 01/10/12; released: Feb 29, 2012
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 = username
package.path = '/home/'..username..'/.v9000_config.lua'
require '.v9000_config'
--INITIALIZE SETTINGS-- need only be run once
get=1
run=1
general_settings,tanslation_tables,translate=weather_settings()
--GET DAILY WEATHER FUNCTION
function getdaily(l,u)
if u=="F" then
web="http://www.intellicast.com/Local/Forecast.aspx?unit=F&location="..l
elseif u=="C" then
web="http://www.intellicast.com/Local/Forecast.aspx?unit=C&location="..l
end
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
local allweatherdata=f:read("*a")
f:close()
local allweatherdata=string.gsub(allweatherdata,"[\n\r]","")
if string.find(allweatherdata,">10 Day Forecast ")~=nil then
local a,b,allweather=string.find(allweatherdata,">10 Day Forecast (.*)MarginBottom")
local a,b,nowweather=string.find(allweatherdata,">Current Conditions (.*)>Local Information</div>")
if string.find(allweatherdata,"Severe Weather Alert!")~=nil then
alert=1
else
alert=0
end
--get location
local a,b,wl=string.find(allweatherdata,"<title>%s*Intellicast%s%p%s(.*)</title>")
local weather_location=string.gsub(wl," Extended Forecast in",",")
return 1,allweather,nowweather,alert,weather_location
else
return 0,0,0,0,0
end--if testall==1
end--daily
--GET ALERT DATA FUNCTION
function getalert(l)
print ("getting alert data")
local f=io.popen("curl --max-time 60 'http://www.intellicast.com/Storm/Severe/Bulletins.aspx?location="..l.."' | sed 's/%//g'")
local alertdata=f:read("*a")
f:close()
local alertdata=string.gsub(alertdata,"[\n\r]","")
if string.find(alertdata,"%a")~=nil then
return alertdata,1
else
return 0,0
end
end--function alert
--GET HOUR DATA FUNCTION
function gethourdata(l,u)
if u=="F" then
web="http://www.intellicast.com/Local/Hourly.aspx?unit=F&location="..l
elseif u=="C" then
web="http://www.intellicast.com/Local/Hourly.aspx?unit=C&location="..l
end
--get todays hours
local f=io.popen("curl --max-time 60 '"..web.."' | sed 's/%//g'")
local allhour=f:read("*a")
f:close()
if string.find(allhour,"Today's Hourly Forecast Report")~=nil then
local allhour=string.gsub(allhour,"[\n\r]","")
local s,f,hdatatoday=string.find(allhour,"Today's Hourly Forecast Report(.*)chartFooter")
--get tomorrows hours
local f=io.popen("curl --max-time 60 '"..web.."&day=Tomorrow' | sed 's/%//g'")
local allhour=f:read("*a")
f:close()
local allhour=string.gsub(allhour,"[\n\r]","")
local s,f,hdatatomorrow=string.find(allhour,"Today's Hourly Forecast Report(.*)chartFooter")
local hdata1=hdatatoday:split("<td")
local hdata2=hdatatomorrow:split("<td")
return hdata1,hdata2,1
else
return 0,0,0
end
end--hourlydata function
--## MAIN FUNCTION ###########
function conky_weather()--##########
--## SETUP CONKY WINDOW ################################
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
--#########################################################################################################
local tries=general_settings.tries or 3
if get<tries then--run the script
--############start of timed section#######################################################################
--#########################################################################################################
local timer=(updates %tonumber(general_settings.update_interval))
if timer==0 or run==1 then--######
--##GET DAILY WEATHER DATA#####################################
local location=general_settings.location
local units=general_settings.units or "F"
print ("gathering data with curl. Attempt "..get.." of "..tries)
testall,allweather,nowweather,alert,weather_location=getdaily(location,units)
--#######################################
if testall==1 then --curl worked and script should continue
run=nil
continue=1
get=1
elseif testall==0 then
get=get+1
continue=0
run=1
runtemplate=0
end
--##GET ALERT DATA#####################################
alert_check=general_settings.alert_check
if alert_check==1 and alert==1 and continue==1 then --only works if bit before worked, and alerts are on and there are alerts to get
alertdata,alerttest=getalert(location)
--#######################################
if alerttest==1 then --curl worked and script should continue
run=nil
continue=1
get=1
elseif alerttest==0 then
get=get+1
continue=0
run=1
runtemplate=0
end
end--alert section
--##GET HOUR DATA#####################################
gethour=general_settings.gethour or 0
if gethour==1 and continue==1 then
print ("getting hourly data")
hdtab1,hdtab2,htest=gethourdata(location,units)
if htest==1 then --curl worked and script should continue
run=nil
continue=1
get=1
elseif htest==0 then
get=get+1
continue=0
run=1
runtemplate=0
end
end
--#########################################################################
end--of timed data gathering section
--#########################################################################
--START PROCESSING ###########################################################################
if continue==1 then--all instances of curl worked
--START PROCESSING ###########################################################################
local weathericons=general_settings.weathericons
local con_short=general_settings.con_short
local visibility_unit=general_settings.visibility_unit
local wind_mph_unit=general_settings.wind_mph_unit
local wind_km_unit=general_settings.wind_km_unit
local wind_kts_unit=general_settings.wind_kts_unit
local ceiling_unit=general_settings.ceiling_unit
local wind_degrees_unit=general_settings.wind_degrees_unit
--#########################################################################
--LOAD TRANSLATE TABLES IF TRANSLATE SETTING = 1
if translate==1 then
monthshort=translation_tables.monthshort
monthnames=translation_tables.monthnames
dayshort=translation_tables.dayshort
daynames=translation_tables.daynames
neswtext=translation_tables.neswtext
tsuffix=translation_tables.tsuffix
uvindextext=translation_tables.uvindextext
moonphases=translation_tables.moonphases
additional=translation_tables.additional
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
--get month number from month name
local monthnum={January=1,February=2,March=3,April=4,May=5,June=6,July=7,August=8,September=9,October=10,November=11,December=12}
--#########################################################################
--process data tables
--intellicast to conky weather icon conversion
local 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
local 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
local 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
local 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
local 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_num={}
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={}
forecast_year_2d={}
forecast_year_4d={}
--#########################################################################
--## FORECAST WEATHER #######################################################################################################################################
--## FORECAST WEATHER #######################################################################################################################################
--## FORECAST WEATHER #######################################################################################################################################
--## FORECAST WEATHER #######################################################################################################################################
--extract information into tables
local start=0
local f=1
local daycount=1
while f~=nil do
local year2d,year4d=getyear(daycount)
table.insert(forecast_year_2d,year2d)
table.insert(forecast_year_4d,year4d)
--match forecast day name and date
local s,f,t=string.find(allweather,"<td%scolspan=%p2%p><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*)$")
--ser 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
if tonumber(monthnum[month])<10 then
mnum="0"..monthnum[month]
else
mnum=monthnum[month]
end
table.insert(forecast_month_num,mnum)
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_clear/(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
if cons==k then
cons=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]*)°",start)
table.insert(high_temp,t)
--match low temp
local s,f,t=string.find(allweather,"\"Lo\">([%p%d]*)°",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 coveage
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*)°")
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
daycount=daycount+1
end--while
--#########################################################################
--## CURRENT WEATHER #######################################################################################################################################
--## CURRENT WEATHER #######################################################################################################################################
--## CURRENT WEATHER #######################################################################################################################################
--## CURRENT WEATHER #######################################################################################################################################
--format now weather
now={}
local 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"}
--<div style="float:right;color:#FFF;">
local s,f,tnow=string.find(nowweather,"<div%sstyle=%pfloat%pright%pcolor%p%pFFF%p%p>%s%sAs%sof%s([%d%p%a%s]*)%s%(Local%sTime%)")
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)
if tonumber(monthnum[mnth])<10 then
mnumn="0"..monthnum[mnth]
else
mnumn=monthnum[mnth]
end
now["month_num"]=mnumn
--get year
local s,f,t=string.find(tnow,"%a%a%a%s(%d%d%d%d)")
now["year"]=t
--get weather icon
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]
--class=%pIcon%p /> ([%a%s]*)%s*</td>
local s,f,t=string.find(nowweather,"class=%pIcon%p /> ([%a%s%p]*)%s*%s*</td>%s*<td class=%pEmpty%p> ")
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
if cons==k then
cons=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]*)°")
now["temp"]=t
local s,f,t=string.find(nowweather,">Feels Like: ([%p%d]*)°</a>")
now["feels_like"]=t
local s,f,t=string.find(nowweather,">Wind Chill: </a></td>%s*<td>([%p%d]*)°</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]*)°</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]*)°</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 #################################################
--[[1 mile per hour = 0.869 international nautical mile per hour (knot)
1 mile per hour = 1.609 kilometers per hour
1 mile per hour = 0.4470 meter per second
1 knot = 1.852 kilometers per hour
1 knot = 0.5144 meter per second
1 meter per second = 3.6 kilometers per hour]]
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*)°")
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 ########################################################
--[[ 1 inch of mercury = 25.4 mm of mercury = 33.86 millibars
= 33.86 hectoPascals]]
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
--<strong>1 PM</strong><br />%s*P Cloudy%s*</td>%s*<td class=%pHour%p
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]*[%a%p])%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
if cons==k then
cons=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
--><strong>-5°</strong></td>
local a,b,t=string.find(hfc,"><strong>([%p%d]*)°</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
--<strong>1 PM</strong><br />%s*P Cloudy%s*</td>%s*<td class=%pHour"%p
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*([%p%s%a]*[%a%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
if cons==k then
cons=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
--><strong>-5°</strong></td>
local a,b,t=string.find(hfc,"><strong>([%p%d]*)°</strong></td>",start)
now["fc_hour2_temp"]=t
--end of hour2 data gathering--repeat 1 more times
--get hourly forecast options hour3--------------------
local start=tonumber(b)
--get time and conditions
--<strong>1 PM</strong><br />%s*P Cloudy%s*</td>%s*<td class=%pHour"%p
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*([%p%s%a]*[%a%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
if cons==k then
cons=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
--><strong>-5°</strong></td>
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 ###############################################################
--## ALERTS ###############################################################
--## ALERTS ###############################################################
--## ALERTS ###############################################################
if alert_check==1 then
--set tables
alert_type={}
alert_issued={}
if alert==1 then
alert_icon=weathericons.."icon_alert_1.gif"
--extract information into tables
--get alert line
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,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--alert==1
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 ###########################################
--#########################################################################
--## HOURLY ###############################################################
--## HOURLY ###############################################################
--## HOURLY ###############################################################
--## HOURLY ###############################################################
if gethour==1 then
--setup tables
forecast_hour={}--number and suffix
forecast_hour_12={}--just number in 12 hour format
forecast_hour_ampm={}--either AM or PM
forecast_hour_24={}--just hour in 24 format
hour_temp={}
hour_windchill={}
hour_heatindex={}
hour_uvindex_num={}
hour_uvindex_txt={}
hour_dewpoint={}
hour_humidity={}
hour_precipitation={}
hour_snow={}
hour_clouds={}
hour_visibility_mi={}
hour_visibility_km={}
hour_wind_nsew={}
hour_wind_mph={}
hour_weather_icon={}
hour_weather_font={}
hour_conditions={}
hour_conditions_short={}
hour_count={}
hour_day_num={}
hour_day_txt={}
hour_day_txt_short={}
hour_month_num={}
hour_month_txt={}
hour_month_txt_short={}
for i=15,(#hdtab1-1) do
if (i %14)==1 then--time
local s,f,time=string.find(hdtab1[i],">([%d%s%a]*)<")
table.insert(forecast_hour,time)
local space=string.find(time,"%s")
local num=string.sub(time,1,space-1)
table.insert(forecast_hour_12,num)
local suf=string.sub(time,space+1,string.len(time))
table.insert(forecast_hour_ampm,suf)
table.insert(forecast_hour_24,convert24(num,suf))
elseif (i %14)==2 then--temp
local s,f,temp=string.find(hdtab1[i],">(.*)°%p*</td>")
table.insert(hour_temp,temp)
elseif (i %14)==3 then--windchill
local s,f,chill=string.find(hdtab1[i],">(.*)°</td>")
table.insert(hour_windchill,chill)
elseif (i %14)==4 then--heatindex
local s,f,heat=string.find(hdtab1[i],">(.*)°</td>")
table.insert(hour_heatindex,heat)
elseif (i %14)==5 then--uvindex-->2<br />Low</td>
local s,f,uvnum=string.find(hdtab1[i],">(.*)<br")
table.insert(hour_uvindex_num,uvnum)
local s,f,uvtxt=string.find(hdtab1[i],"%s/>(.*)</td>")
table.insert(hour_uvindex_txt,uvtxt)
elseif (i %14)==6 then--dew point
local s,f,dew=string.find(hdtab1[i],">(.*)°</td>")
table.insert(hour_dewpoint,dew)
elseif (i %14)==7 then--humidity
local s,f,hum=string.find(hdtab1[i],">(.*)</td>")
table.insert(hour_humidity,hum)
elseif (i %14)==8 then--precipitation
local s,f,ppt=string.find(hdtab1[i],">(.*)</td>")
table.insert(hour_precipitation,ppt)
elseif (i %14)==9 then--snow
local s,f,snow=string.find(hdtab1[i],">(.*)</td>")
table.insert(hour_snow,snow)
elseif (i %14)==10 then--clouds
local s,f,cloud=string.find(hdtab1[i],">(.*)</td>")
table.insert(hour_clouds,cloud)
elseif (i %14)==11 then--visibility
local s,f,vmi=string.find(hdtab1[i],">(.*)<br")
table.insert(hour_visibility_mi,vmi)
local s,f,vkm=string.find(hdtab1[i],"%s/>(.*)</td>")
table.insert(hour_visibility_km,vkm)
elseif (i %14)==12 then--wind
local s,f,nsew=string.find(hdtab1[i],">(.*)<br")
table.insert(hour_wind_nsew,nsew)
local s,f,wmph=string.find(hdtab1[i],"%s/>(.*)</td>")
table.insert(hour_wind_mph,wmph)
elseif (i %14)==13 then--icon
local s,f,t=string.find(hdtab1[i],"App_Images/32_clear/(wx_[%d]*).png\" alt=")
--convert to conkyweather icon
table.insert(hour_weather_icon,weathericons..wimage[t]..".png")
--convert to weather font
table.insert(hour_weather_font,wfont[t])
elseif (i %14)==0 then--conditions
local s,f,cons=string.find(hdtab1[i],">(.*)</td>")
table.insert(hour_conditions,cons)
--set short versions--------------------------------
for k,v in pairs(con_short) do
if cons==k then
cons=v
end
end
table.insert(hour_conditions_short,cons)
table.insert(hour_count,"count")
table.insert(hour_day_num,forecast_date[1])
table.insert(hour_day_txt,forecast_day[1])
table.insert(hour_day_txt_short,dayshort[forecast_day[1]])
table.insert(hour_month_num,monthnum[forecast_month[1]])
table.insert(hour_month_txt,forecast_month[1])
table.insert(hour_month_txt_short,monthshort[forecast_month[1]])
end
end--for
--for i=15,(#hdtab2-1) do
i=15
while #hour_count<24 do
if (i %14)==1 then--time
local s,f,time=string.find(hdtab2[i],">([%d%s%a]*)<")
table.insert(forecast_hour,time)
local space=string.find(time,"%s")
local num=string.sub(time,1,space-1)
table.insert(forecast_hour_12,num)
local suf=string.sub(time,space+1,string.len(time))
table.insert(forecast_hour_ampm,suf)
table.insert(forecast_hour_24,convert24(num,suf))
elseif (i %14)==2 then--temp
local s,f,temp=string.find(hdtab2[i],">(.*)°%p*</td>")
table.insert(hour_temp,temp)
elseif (i %14)==3 then--windchill
local s,f,chill=string.find(hdtab2[i],">(.*)°</td>")
table.insert(hour_windchill,chill)
elseif (i %14)==4 then--heatindex
local s,f,heat=string.find(hdtab2[i],">(.*)°</td>")
table.insert(hour_heatindex,heat)
elseif (i %14)==5 then--uvindex-->2<br />Low</td>
local s,f,uvnum=string.find(hdtab2[i],">(.*)<br")
table.insert(hour_uvindex_num,uvnum)
local s,f,uvtxt=string.find(hdtab2[i],"%s/>(.*)</td>")
table.insert(hour_uvindex_txt,uvtxt)
elseif (i %14)==6 then--dew point
local s,f,dew=string.find(hdtab2[i],">(.*)°</td>")
table.insert(hour_dewpoint,dew)
elseif (i %14)==7 then--humidity
local s,f,hum=string.find(hdtab2[i],">(.*)</td>")
table.insert(hour_humidity,hum)
elseif (i %14)==8 then--precipitation
local s,f,ppt=string.find(hdtab2[i],">(.*)</td>")
table.insert(hour_precipitation,ppt)
elseif (i %14)==9 then--snow
local s,f,snow=string.find(hdtab2[i],">(.*)</td>")
table.insert(hour_snow,snow)
elseif (i %14)==10 then--clouds
local s,f,cloud=string.find(hdtab2[i],">(.*)</td>")
table.insert(hour_clouds,cloud)
elseif (i %14)==11 then--visibility
local s,f,vmi=string.find(hdtab2[i],">(.*)<br")
table.insert(hour_visibility_mi,vmi)
local s,f,vkm=string.find(hdtab2[i],"%s/>(.*)</td>")
table.insert(hour_visibility_km,vkm)
elseif (i %14)==12 then--wind
local s,f,nsew=string.find(hdtab2[i],">(.*)<br")
table.insert(hour_wind_nsew,nsew)
local s,f,wmph=string.find(hdtab2[i],"%s/>(.*)</td>")
table.insert(hour_wind_mph,wmph)
elseif (i %14)==13 then--icon
local s,f,t=string.find(hdtab2[i],"App_Images/32_clear/(wx_[%d]*).png\" alt=")
--convert to conkyweather icon
table.insert(hour_weather_icon,weathericons..wimage[t]..".png")
--convert to weather font
table.insert(hour_weather_font,wfont[t])
elseif (i %14)==0 then--conditions
local s,f,cons=string.find(hdtab2[i],">(.*)</td>")
table.insert(hour_conditions,cons)
--set short versions--------------------------------
for k,v in pairs(con_short) do
if cons==k then
cons=v
end
end
table.insert(hour_conditions_short,cons)
table.insert(hour_count,"count")
table.insert(hour_day_num,forecast_date[2])
table.insert(hour_day_txt,forecast_day[2])
table.insert(hour_day_txt_short,dayshort[forecast_day[2]])
table.insert(hour_month_num,monthnum[forecast_month[2]])
table.insert(hour_month_txt,forecast_month[2])
table.insert(hour_month_txt_short,monthshort[forecast_month[2]])
end
i=i+1
end--for
end--if gethour
--#############################################################
--###############end of data processing########################
--###############end of data processing########################
--###############end of data processing########################
--###############end of data processing########################
--###############end of data processing########################
--#############################################################
if testing==0 then--script not in testing
continue=0--processing turned off
runtemplate=1--template turned on
print ("processing complete")
elseif testing==1 then
continue=1
runtemplate=1
end--if testing ==0
--##############################################################
end--if continue==1 of data processing section##################
--##############################################################
if runtemplate==1 then
_G.weather_script()
end
--##############################################################
else--if get is greater or equal to 4 then curl did not work
print ("unable to gather data, check connection and try again")
end--if get <4
--###UNCOMMENT THE BELOW LINE TO ENABLE CPU DELAY###############
--end--####### end of if updates>5 #############################
--##############################################################
--clean up
web=nil
allweather=nil
nowweather=nil
alert=nil
--weather_location=nil
alertdata=nil
alerttest=nil
hdtab1=nil
hdtab2=nil
htest=nil
testall=nil
gethour=nil
alert_check=nil
monthshort=nil
monthnames=nil
dayshort=nil
daynames=nil
neswtext=nil
tsuffix=nil
uvindextext=nil
moonphases=nil
additional=nil
day=nil
month=nil
cons=nil
suf=nil
utx=nil
t=nil
tnesw=nil
mnth=nil
tc=nil
unlset=nil
tg=nil
tgkm=nil
tgkts=nil
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
--######################################
end-- end main function ################
--######################################
--######################################
--######################################
--######################################
--######################################
--######################################
function round(num)
local idp=tonumber(general_settings.decimal_places)
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,a,f,fs,x,y,txt,j ##################################################
c=nil
c=(txj.c or default_color)
a=nil
a=(txj.a or default_alpha)
f=nil
f=(txj.f or default_font)
fs=nil
fs=(txj.fs or default_font_size)
x=nil
x=(txj.x or 0)
y=nil
y=(txj.y or 0)
txt=nil
txt=(txj.txt or "set txt")
j=nil
j=(txj.j or "l")
local function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function
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
cairo_set_source_rgba (cr,col(c,a))
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_show_text (cr,txt)
cairo_stroke (cr)
nextx=nil
nextx=adx+x
return nextx
end--function xout ###################################################################
function out(txj)--c,a,f,fs,face,x,y,txt,hj,vj,ro ##################################################
local extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
--#########################################################################################################
local function color(col,alp)
return ((col / 0x10000) % 0x100) / 255, ((col / 0x100) % 0x100) / 255, (col % 0x100) / 255, alp
end
--#########################################################################################################
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 hj=txj.hj or default_hj or "l"
local vj=txj.vj or default_vj or "n"
local ro=txj.ro or defaukt_ro or 0
local face=txj.face or default_face or "normal"
--set face
if face=="normal" then
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
elseif face=="bold" then
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
elseif face=="italic" then
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_NORMAL);
elseif face=="bolditalic" then
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
else
print ('face not set correctly - "normal","bold","italic","bolditalic"')
end
cairo_set_font_size (cr, fs)
cairo_text_extents(cr,txt,extents)
local wx=extents.x_advance
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 - l, c, r
if hj=="l" then
x=x-bx
rad=0
elseif hj=="c" then
x=x-((wx-bx)/2)-bx
rad=(wx-bx)/2
elseif hj=="r" then
x=x-wx
rad=wx-bx
else
print ("hj not set correctly - l, c, r")
end
--vj. n=normal, nb=normal-ybearing, m=middle, mb=middle-ybearing, t=top
if vj=="n" then
y=y
rad2=0
ry=by
elseif vj=="nb" then
y=y-by
rad2=-by
ry=by
elseif vj=="m" then
y=y+((hy-by)/2)
rad2=((hy-by)/2)
ry=((hy-by)/2)-by
elseif vj=="mb" then
y=y+(hy/2)-by
rad2=(hy/2)-by
ry=((hy-by)/2)-by
elseif vj=="t" then
y=y+hy-by
rad2=hy-by
ry=0+by
else
print ("vj not set correctly - n, nb, m, mb, t")
end
--rotation
if ro~=0 then
local point2=(math.pi/180)*(ro-180)
local x2=tx+rad2*(math.sin(point2))
local y2=ty-rad2*(math.cos(point2))
local point=(math.pi/180)*(ro-90)
local x1=x2+rad*(math.sin(point))
local y1=y2-rad*(math.cos(point))
cairo_save (cr)
cairo_translate (cr,x1,y1)
cairo_rotate(cr,(math.pi/180)*ro)
cairo_set_source_rgba (cr,color(c,a))
cairo_show_text (cr,txt)
cairo_stroke (cr)
cairo_restore (cr)
else
cairo_move_to (cr,x,y)
cairo_set_source_rgba (cr,color(c,a))
cairo_show_text (cr,txt)
cairo_stroke (cr)
end--if ro
end--function out ###################################################################
function image(im)--#################################################################
x=nil
x=(im.x or 0)
y=nil
y=(im.y or 0)
w=nil
w=(im.w or default_image_width)
h=nil
h=(im.h or default_image_height)
file=nil
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
imlib_context_set_image(show)
if tonumber(w)==0 then
width=imlib_image_get_width()
else
width=tonumber(w)
end
if tonumber(h)==0 then
height=imlib_image_get_height()
else
height=tonumber(h)
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width, height)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(x, y)
imlib_free_image()
show=nil
end--function image ##################################################################
function convert24(tm,suf)
local tmlen=string.len(tm)
local colon=string.find(tm,":")
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
function getyear(n)
--get current month
local mn=tonumber(os.date("%m"))
--get current day
local td=tonumber(os.date("%d"))
if mn==12 and td+(n-1)>31 then
return tonumber(os.date("%g"))+1,tonumber(os.date("%G"))+1
else
return tonumber(os.date("%g")),tonumber(os.date("%G"))
end
end--of function
--END OF SCRIPT
Bookmarks