This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Weather service not working anymore?
#29
Thank you Admin
If someone is interested in then there's yrno script below (warning: uses obsolete API)
Function minmax_temp_tomorrow returns lowest and highest temperature for tomorrow. The script is simple and ignores time shift.
Code:
require('socket.http')

forecast = {}

function parsetag(parser, tag, attributes)
 if tag == 'time' then
   table.insert(forecast, {})
   forecast[ #forecast ].from=attributes.from
   forecast[ #forecast ].to=attributes.to
   forecast[ #forecast ].period=attributes.period
 elseif tag == 'symbol' then
   forecast[ #forecast ].symbol = attributes.name
 elseif tag == 'precipitation' then
   forecast[ #forecast ].precipitation = attributes.value
 elseif tag == 'windDirection' then
   forecast[ #forecast ].wind_direction = attributes.code
 elseif tag == 'windSpeed' then
   forecast[ #forecast ].wind_speed = attributes.mps
 elseif tag == 'temperature' then
   forecast[ #forecast ].temperature = attributes.value
 elseif tag == 'pressure' then
   forecast[ #forecast ].pressure = attributes.value
 end
end

function yrno_fetch()
 local url = 'http://www.yr.no/place/Czech_Republic/Prague/Prague/varsel.xml'
 local data, err = socket.http.request(url)

 if data then
   require('lxp').new({
     StartElement = parsetag
   }):parse(data)
   
   
 else
   alert('Fetch failed: ' .. tostring(err))
 end
end

function minmax_temp_tomorrow()
 local ld_minTemp
 local ld_maxTemp
 local next_day={}

 yrno_fetch()
 if (not forecast) then
   return
 end
 local ll_tomorrow=os.time()+24*3600 -- tomorrow as long
 local lt_tomorrow= os.date("*t",ll_tomorrow) -- tomorrow as table for use if forecast_write

 --gets date of tomorrow
 local ls_match=os.date("%Y--%m--%d",ll_tomorrow)

 
for index, value in ipairs(forecast) do
   if (value.from:match("^"..ls_match)) then
     local ld_temp=tonumber(value.temperature)
     if (ld_minTemp == nil) then
       ld_minTemp=ld_temp
     end
     if (ld_maxTemp == nil) then
       ld_maxTemp=ld_temp
     end
     if (ld_temp<ld_minTemp or index==1) then
       ld_minTemp=ld_temp
     end
     if (ld_temp>ld_maxTemp or index==1) then
       ld_maxTemp=ld_temp
     end
   end
end
  return ld_minTemp,ld_maxTemp,lt_tomorrow
end
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply


Messages In This Thread
RE: Weather service not working anymore? - by Thomas - 08.01.2019, 16:21

Forum Jump: