Posts: 4657
Threads: 24
Joined: Aug 2017
Reputation:
212
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
------------------------------
Ctrl+F5
Posts: 4657
Threads: 24
Joined: Aug 2017
Reputation:
212
My script still works.
------------------------------
Ctrl+F5
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
require('ssl.https')
require('json')
data = ssl.https.request('http://weerlive.nl/api/json-10min.php?locatie=' ..plaatsnaam)
datatable = json.pdecode(data)
datatable = datatable['liveweer'][1]
log(datatable)
If you use something like this, how do you deploy it and how do you extract this to groupo adresses?
Posts: 4657
Threads: 24
Joined: Aug 2017
Reputation:
212
I tried like that you have to put coordinate of location as longitude and latitude.
Code:
require('ssl.https')
require('json')
data = ssl.https.request('https://api.met.no/weatherapi/locationforecast/2.0/.json?lat=51.28&lon=-0.75')
datatable = json.pdecode(data)
log(datatable.properties.timeseries[1].data.instant.details.air_temperature)
------------------------------
Ctrl+F5
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Firefox can display JSON data in a structured way. Or just copy JSON from the URL and use any online JSON viewer.