01.10.2017, 17:11
(This post was last modified: 02.10.2017, 07:08 by Erwin van der Zwart.)
Hi,
Just paste the url from the request in your browser, there you see the original XML structure.
For better API you could try something like this as it has real time forecast and hourly data http://www.apixu.com (or any other of the 1000 available), another plus is that it also has JSON data so you don't need the XML parser to get a LUA table. You can use this free if you don’t need interval faster then 10 minutes (= max 5000 calls a month)
Here is a sample to get data from the apixu api:
I'm not sure hour 1 is next hour or 1:00 so maybe you need to add small algorithm to compare with 'now' and selected day / hour from the table
BR,
Erwin
Just paste the url from the request in your browser, there you see the original XML structure.
For better API you could try something like this as it has real time forecast and hourly data http://www.apixu.com (or any other of the 1000 available), another plus is that it also has JSON data so you don't need the XML parser to get a LUA table. You can use this free if you don’t need interval faster then 10 minutes (= max 5000 calls a month)
Here is a sample to get data from the apixu api:
Code:
require 'ssl.https'
require 'json'
-- Set your API key here
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
-- Set here your location
location = 'Amsterdam'
-- Request data from API
r,c,h,s = ssl.https.request('https://api.apixu.com/v1/forecast.json?key=' .. api_key .. '=' .. location)
-- Decode JSON data to LUA table
if r then
result = json.pdecode(r)
else
alert('Could not fetch data')
return
end
-- Get next hour temperature
temperature_in_one_hour = result['forecast']['forecastday'][1]['hour'][1]['temp_c']
-- Do something with the received temperature
log(temperature_in_one_hour)
I'm not sure hour 1 is next hour or 1:00 so maybe you need to add small algorithm to compare with 'now' and selected day / hour from the table
BR,
Erwin