LogicMachine Forum
Important: Apixu switching to the new API - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Important: Apixu switching to the new API (/showthread.php?tid=2258)



Important: Apixu switching to the new API - admin - 02.10.2019

Apixu is switching their API to a new service called Weatherstack.

This means that you have to modify your weather scripts with new URL and API keys. Unfortunately, their free tier does not provide any forecast data anymore, only current conditions. HTTPS is also not provided for free tier.

Code:
require('json') http = require('socket.http') escape = require('socket.url').escape key = 'your_key_here' location = 'your_location_here' url = 'http://api.weatherstack.com/current?access_key=%s&query=%s' 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')   return end if data.error then   log('error', data.error)   return end current = data.current -- temperature grp.write('32/1/1', current.temperature) -- "feels like" temperature grp.write('32/1/2', current.feelslike) -- humidity as percentage grp.write('32/1/3', current.humidity) -- wind speed in kilometers per hour grp.write('32/1/4', current.wind_speed) -- uv index grp.write('32/1/5', current.uv_index) -- weather condition text grp.write('32/1/6', current.weather_descriptions[1]) -- pressure grp.write('32/1/7', current.pressure) -- precipitation amount grp.write('32/1/8', current.precip)