Here is my script that gets a 5 day forcast using the Yahoo RSS feed.
Converted to load to my ADI Leopard touch screen using the Ocelot plugin.
Just add your 5 digit zipcode for your area!Code:--Script to grab 5 day forecast --using Yahoo RSS weather feed function Getforcast() FC = luacom.CreateObject("Msxml2.DOMDocument") FC.async = 0 FC:load ("http://xml.weather.yahoo.com/forecastrss/93720_f.xml") if FC.parseError.errorcode ~=0 then print(FC.parseError.reason) end weather = {} weather["day"] = {d,dt,hi,lo,cond,code} node = FC:SelectSingleNode("//item/yweather:forecast") for i = 1, 5 do weather.day[i] = {d,dt,hi,lo,cond,code} weather.day[i].d = node.Attributes:getNamedItem("day").nodevalue weather.day[i].dt = node.Attributes:getNamedItem("date").nodevalue weather.day[i].hi = node.Attributes:getNamedItem("high").nodevalue weather.day[i].lo = node.Attributes:getNamedItem("low").nodevalue weather.day[i].cond = node.Attributes:getNamedItem("text").nodevalue weather.day[i].code = node.Attributes:getNamedItem("code").nodevalue if weather.day[i].hi == "N/A" then weather.day[i].hi = 0 end node=node.nextSibling end --Icon conversions to use with ADI Leopard touch screen for n = 1, 5 do --Sunny if weather.day[n].code=="31" then weather.day[n].code=31 end if weather.day[n].code=="32" then weather.day[n].code=31 end if weather.day[n].code=="36" then weather.day[n].code=31 end if weather.day[n].code=="44" then weather.day[n].code=31 end --Partial Sun if weather.day[n].code=="23" then weather.day[n].code=32 end if weather.day[n].code=="24" then weather.day[n].code=32 end if weather.day[n].code=="29" then weather.day[n].code=32 end if weather.day[n].code=="30" then weather.day[n].code=32 end --Scattered Showers if weather.day[n].code=="39" then weather.day[n].code=33 end if weather.day[n].code=="41" then weather.day[n].code=33 end if weather.day[n].code=="45" then weather.day[n].code=33 end if weather.day[n].code=="48" then weather.day[n].code=33 end --Cloudy if weather.day[n].code=="26" then weather.day[n].code=34 end if weather.day[n].code=="27" then weather.day[n].code=34 end if weather.day[n].code=="28" then weather.day[n].code=34 end --Showers if weather.day[n].code=="11" then weather.day[n].code=35 end if weather.day[n].code=="12" then weather.day[n].code=35 end if weather.day[n].code=="40" then weather.day[n].code=35 end --Hail/Ice if weather.day[n].code=="5" then weather.day[n].code=36 end if weather.day[n].code=="6" then weather.day[n].code=36 end if weather.day[n].code=="7" then weather.day[n].code=36 end if weather.day[n].code=="8" then weather.day[n].code=36 end if weather.day[n].code=="9" then weather.day[n].code=36 end if weather.day[n].code=="10" then weather.day[n].code=36 end if weather.day[n].code=="13" then weather.day[n].code=36 end if weather.day[n].code=="14" then weather.day[n].code=36 end if weather.day[n].code=="15" then weather.day[n].code=36 end if weather.day[n].code=="16" then weather.day[n].code=36 end if weather.day[n].code=="18" then weather.day[n].code=36 end if weather.day[n].code=="25" then weather.day[n].code=36 end if weather.day[n].code=="42" then weather.day[n].code=36 end if weather.day[n].code=="43" then weather.day[n].code=36 end if weather.day[n].code=="46" then weather.day[n].code=36 end --Thunderstorms if weather.day[n].code=="0" then weather.day[n].code=37 end if weather.day[n].code=="1" then weather.day[n].code=37 end if weather.day[n].code=="2" then weather.day[n].code=37 end if weather.day[n].code=="3" then weather.day[n].code=37 end if weather.day[n].code=="4" then weather.day[n].code=37 end if weather.day[n].code=="17" then weather.day[n].code=37 end if weather.day[n].code=="35" then weather.day[n].code=37 end if weather.day[n].code=="37" then weather.day[n].code=37 end if weather.day[n].code=="38" then weather.day[n].code=37 end if weather.day[n].code=="47" then weather.day[n].code=37 end --Foggy if weather.day[n].code=="20" then weather.day[n].code=38 end --Hazy if weather.day[n].code=="19" then weather.day[n].code=39 end if weather.day[n].code=="21" then weather.day[n].code=39 end if weather.day[n].code=="22" then weather.day[n].code=39 end if weather.day[n].code=="33" then weather.day[n].code=39 end if weather.day[n].code=="34" then weather.day[n].code=39 end end --print results to check in Lua Console for i = 1, 5 do print ("----DAY “..i..”-------------------------------") print (weather.day[i].d.." "..weather.day[i].dt) print ("----Conditions----") print ("conditions = "..weather.day[i].cond) print ("high "..weather.day[i].hi) print ("low "..weather.day[i].lo) print ("icon "..weather.day[i].code) end --Send data to ADI Leopard Touch Screen if os.date("%H")<"12" then Ocelot:SetVar(50, weather.day[1].hi) end Ocelot:SetVariable(52, weather.day[2].hi) Ocelot:SetVariable(54, weather.day[3].hi) Ocelot:SetVariable(56, weather.day[4].hi) Ocelot:SetVariable(58, weather.day[5].hi) Ocelot:SetVariable(51, weather.day[1].lo) Ocelot:SetVariable(53, weather.day[2].lo) Ocelot:SetVariable(55, weather.day[3].lo) Ocelot:SetVariable(57, weather.day[4].lo) Ocelot:SetVariable(59, weather.day[5].lo) Ocelot:SetVariable(36, weather.day[2].code) Ocelot:SetVariable(37, weather.day[3].code) Ocelot:SetVariable(38, weather.day[4].code) Ocelot:SetVariable(39, weather.day[5].code) end Getforcast() collectgarbage ()


Reply With Quote