Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --noaa weather mrpeachy nov 2011
- require 'cairo'
- require 'imlib2'
- ------------------------------------------------------------------------------
- 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
- --------------------------------------------------------------------------------
- function conky_weather()
- 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
- --#########################################################################################################
- --SETUP--SETUP--SETUP--SETUP--SETUP--SETUP--SETUP--SETUP--SETUP--SETUP--SETUP
- secs=600--set update interval
- directory="/home/bkberger/wicon"--directory to store weather icons
- web="http://forecast.weather.gov/MapClick.php?lat=36.070955420413306&lon=-119.03626441955566"
- timer=(updates %secs)+1
- --get web address by going to weather.gov and entering your location in the box
- --#########################################################################################################
- timer=(updates %secs)+1
- if timer==1 or updates==7 then
- local f=io.popen("curl '"..web.."' | grep 'td width' | gawk -F'>' -v RS='<' 'RT{print $NF}'")
- data1=f:read("*a")
- data=string.split(data1,"\n")
- f:close()
- local f=io.popen("curl '"..web.."' | grep -A26 'Current Local Weather' | gawk -F'>' -v RS='<' 'RT{print $NF}' | sed -e 's/^[ \t]*//' -e '/^$/d'")
- data2=f:read("*a")
- current=string.split(data2,"\n")
- f:close()
- conditions=current[6]
- temperature=string.gsub(current[7]," °","°").." "..string.gsub(current[8]," °","°")
- humidity=current[11]
- windspeed=current[14]
- barometer=string.gsub(current[17],""","\"")
- dewpoint=string.gsub(current[20]," °","°")
- windchill=string.gsub(current[23]," °","°")
- --visibility=current[26]
- local f=io.popen("curl '"..web.."' | grep 'td width' | gawk -F'src=\"/images/wtf/' -v RS='\" width=' 'RT{print $NF}'")
- picloc1= f:read("*a")
- picloc=string.split(picloc1,"\n")
- f:close()
- --downloads images used by noaa-----------------------------------
- picnum=#picloc
- for i=1,picnum do
- os.execute("wget -nc --directory-prefix="..directory.." http://forecast.weather.gov/images/wtf/"..picloc[i].."")
- end
- end--timer section
- start=3
- fday1a=data[start]
- fday1b=data[start+1]
- fc1a=data[start+5]
- fc1b=data[start+6]
- ft1=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday2a=data[start]
- fday2b=data[start+1]
- fc2a=data[start+5]
- fc2b=data[start+6]
- ft2=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday3a=data[start]
- fday3b=data[start+1]
- fc3a=data[start+5]
- fc3b=data[start+6]
- ft3=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday4a=data[start]
- fday4b=data[start+1]
- fc4a=data[start+5]
- fc4b=data[start+6]
- ft4=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday5a=data[start]
- fday5b=data[start+1]
- fc5a=data[start+5]
- fc5b=data[start+6]
- ft5=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday6a=data[start]
- fday6b=data[start+1]
- fc6a=data[start+5]
- fc6b=data[start+6]
- ft6=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday7a=data[start]
- fday7b=data[start+1]
- fc7a=data[start+5]
- fc7b=data[start+6]
- ft7=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday8a=data[start]
- fday8b=data[start+1]
- fc8a=data[start+5]
- fc8b=data[start+6]
- ft8=data[start+7]..string.gsub(data[start+8]," °","°")
- start=start+12
- fday9a=data[start]
- fday9b=data[start+1]
- fc9a=data[start+5]
- fc9b=data[start+6]
- ft9=data[start+7]..string.gsub(data[start+8]," °","°")
- --#####################################
- txpos1=30
- typos1=15
- --current conditions
- --text
- font="Mono"
- fsize=14
- xpos=txpos1
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- -------------------------------------
- text="Current Conditions"
- txt(text,xpos,ypos,font,14,red,green,blue,alpha)
- ypos=38
- fsize=10
- text="Conditions: "..conditions
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=" Temp: "..temperature
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=" Humidity: "..humidity
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text="Wind Speed: "..windspeed
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=" Barometer: "..barometer
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=" Dewpoint: "..dewpoint
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- --text="Visibility: "..visibility
- --txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day1
- --image
- center_x=xpos+27+200
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[1]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+200
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday1a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday1b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc1a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc1b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft1
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day2
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[2]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday2a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday2b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc2a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc2b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft2
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day3
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[3]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday3a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday3b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc3a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc3b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft3
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day4
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[4]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday4a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday4b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc4a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc4b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft4
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day5
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[5]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday5a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday5b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc5a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc5b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft5
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day6
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[6]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday6a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday6b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc6a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc6b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft6
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day7
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[7]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday7a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday7b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc7a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc7b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft7
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day8
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[8]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday8a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday8b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc8a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc8b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft8
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --forecast day9
- --image
- center_x=center_x+70
- center_y=24+35
- w=0
- h=0
- file=directory.."/"..picloc[9]
- image(center_x,center_y,w,h,file)
- --text
- font="Mono"
- fsize=10
- xpos=xpos+70
- ypos=typos1
- red,green,blue,alpha=1,1,1,1
- text=fday9a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fday9b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+72
- text=fc9a
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=fc9b
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- ypos=ypos+fsize+2
- text=ft9
- txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- --#########################################################################################################
- end-- if updates>5
- cairo_destroy(cr)
- cairo_surface_destroy(cs)
- cr=nil
- return ""
- end-- end main function
- function image(center_x,center_y,w,h,file)
- 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
- local iacross=center_x-(width/2)
- local idown=center_y-(height/2)
- 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(iacross, idown)
- imlib_free_image()
- show=nil
- end
- function txt(text,xpos,ypos,font,fsize,red,green,blue,alpha)
- cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
- cairo_set_font_size (cr, fsize)
- cairo_set_source_rgba (cr,red,green,blue,alpha)
- cairo_move_to (cr,xpos,ypos)
- cairo_show_text (cr,text)
- end--function
- function rgb_to_r_g_b(colour,alpha)
- return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
- end
- function conky_draw_bg(r,x,y,w,h,color,alpha)
- if conky_window == nil then return end
- if cs == nil then cairo_surface_destroy(cs) end
- if cr == nil then cairo_destroy(cr) 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)
- cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
- --top left mid circle
- local xtl=x+r
- local ytl=y+r
- --top right mid circle
- local xtr=(x+r)+((w)-(2*r))
- local ytr=y+r
- --bottom right mid circle
- local xbr=(x+r)+((w)-(2*r))
- local ybr=(y+r)+((h)-(2*r))
- --bottom right mid circle
- local xbl=(x+r)
- local ybl=(y+r)+((h)-(2*r))
- -----------------------------
- cairo_move_to (cr,xtl,ytl-r)
- cairo_line_to (cr,xtr,ytr-r)
- cairo_arc(cr,xtr,ytr,r,((2*math.pi/4)*3),((2*math.pi/4)*4))
- cairo_line_to (cr,xbr+r,ybr)
- cairo_arc(cr,xbr,ybr,r,((2*math.pi/4)*4),((2*math.pi/4)*1))
- cairo_line_to (cr,xbl,ybl+r)
- cairo_arc(cr,xbl,ybl,r,((2*math.pi/4)*1),((2*math.pi/4)*2))
- cairo_line_to (cr,xtl-r,ytl)
- cairo_arc(cr,xtl,ytl,r,((2*math.pi/4)*2),((2*math.pi/4)*3))
- cairo_close_path(cr)
- cairo_fill (cr)
- ------------------------------------------------------------
- cairo_surface_destroy(cs)
- cairo_destroy(cr)
- return ""
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement