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?
#42
(18.01.2019, 10:09)Daniel. Wrote: Hi
I'm doing it like that

Code:
require('socket.http')

forecast = {}

function parsetag(parser, tag, attributes)
 if tag == 'time' then
   table.insert(forecast, {})
 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

url = 'http://www.yr.no/place/United_Kingdom/England/Farnborough/varsel.xml'
data, err = socket.http.request(url)

if data then
 require('lxp').new({
   StartElement = parsetag
 }):parse(data)


 grp.update('Weather precipitation', tonumber(forecast[1].precipitation))
 grp.update('Weather symbol', forecast[1].symbol)
 grp.update('Weather windDirection', forecast[1].wind_direction)
 grp.update('Weather windSpeed', tonumber(forecast[1].wind_speed))
 grp.update('Weather temperature', tonumber(forecast[1].temperature))
 grp.update('Weather pressure', tonumber(forecast[1].pressure))

 --log(forecast)
 
else
 alert('Fetch failed: ' .. tostring(err))
end
Looks great, but i still dont understand where to put the GA in. Sorry for the low lewel of knowlegde. Smile
Reply


Messages In This Thread
RE: Weather service not working anymore? - by Tokatubs - 30.01.2019, 20:55

Forum Jump: