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?
#22
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:

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
Reply


Messages In This Thread
RE: Weather service not working anymore? - by Erwin van der Zwart - 01.10.2017, 17:11

Forum Jump: