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 whether you accept or reject these cookies being set.

Weather Apixu
#1
Hello, I created this scrip in several Logic Machine to know meteorological data and they worked correctly until a while ago they no longer work, they could help me find out what the error is or why they don't work.

Thank you

*****************************************************************************************************
--  https://www.apixu.com/

require('json')
https = require('ssl.https')
escape = require('socket.url').escape

key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'  --API KEY  
location = 'Alcobendas'  -- lugar de clima


url = 'https://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))


res = https.request(url)

data = json.pdecode(res)
if type(data) ~= 'table' then
  alert('failed to load weather data')
  log('failed to load weather data')
  return
end

if data.error then
  log('error', data.error)
  return
end

current = data.current
today = data.forecast.forecastday[ 1 ].day
tomorrow = data.forecast.forecastday[ 2 ].day


--INFO UTILIZADA

-- temperature in C
grp.write('15/1/2', current.temp_c)
-- weather condition text
grp.write('15/1/1', current.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/4', today.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('15/1/5', today.maxtemp_c)
-- weather condition text
grp.write('15/1/3', today.condition.text)
-- maximum temperature in celsius for the day
grp.write('15/1/8', tomorrow.maxtemp_c)
-- weather condition text
grp.write('15/1/6', tomorrow.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/7', tomorrow.mintemp_c)
-- "feels like" temperature in C
grp.write('15/1/9', current.feelslike_c)
-- humidity as percentage
grp.write('15/1/12', current.humidity)
-- wind speed in kilometers per hour
grp.write('15/1/11', current.wind_kph)
-- uv index
grp.write('15/1/15', current.uv)
-- pressure in millibars
grp.write('15/1/14', current.pressure_mb)
-- "wind_dir"
grp.write('15/1/10', current.wind_dir)
-- "sunrise"
Reply
#2
See here: https://forum.logicmachine.net/showthrea...8#pid13858
Reply
#3
Hello
I have changed the scrip as it has told me and now in registers I have no error but in registration error I have this message:

User script:15: attempt to index global 'http' (a nil value)
stack traceback:
User script:15: in main chunk


Could you help me since it is a scrip that I need in several machines.

Thank you

*********************************************************************************************************
-- https://www.apixu.com/

require('json')
https = require('ssl.https')
escape = require('socket.url').escape

key = 'My_Api_Key' --API KEY despues de realizar el registro
location = 'Alcobendas' -- lugar de clima


url = 'http://api.apixu.com/v1/forecast.json?key=%s&q=%s&days=2'
url = string.format(url, key, escape(location))


res = http.request(url)

data = json.pdecode(res)
if type(data) ~= 'table' then
alert('failed to load weather data')
log('failed to load weather data')
return
end

if data.error then
log('error', data.error)
return
end

current = data.current
today = data.forecast.forecastday[ 1 ].day
tomorrow = data.forecast.forecastday[ 2 ].day


--INFO UTILIZADA

-- temperature in C
grp.write('15/1/2', current.temp_c)
-- weather condition text
grp.write('15/1/1', current.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/4', today.mintemp_c)
-- maximum temperature in celsius for the day
grp.write('15/1/5', today.maxtemp_c)
-- weather condition text
grp.write('15/1/3', today.condition.text)
-- maximum temperature in celsius for the day
grp.write('15/1/8', tomorrow.maxtemp_c)
-- weather condition text
grp.write('15/1/6', tomorrow.condition.text)
-- minimum temperature in celsius for the day
grp.write('15/1/7', tomorrow.mintemp_c)
-- "feels like" temperature in C
grp.write('15/1/9', current.feelslike_c)
-- humidity as percentage
grp.write('15/1/12', current.humidity)
-- wind speed in kilometers per hour
grp.write('15/1/11', current.wind_kph)
-- uv index
grp.write('15/1/15', current.uv)
-- pressure in millibars
grp.write('15/1/14', current.pressure_mb)
-- "wind_dir"
grp.write('15/1/10', current.wind_dir)
-- "sunrise"
Reply
#4
You are missing this line:
Code:
http = require('socket.http')
Reply


Forum Jump: