08.01.2019, 20:40
(08.01.2019, 16:21)Thomas Wrote: 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
Hi Thomas,
Do you have an example of how to write the forecast to GA? and what datatype the different object needs to be?
BR Even Sundgot.