love2d-signage/nodes/newdash_thread.lua

37 lines
939 B
Lua

local socket = require("socket")
local http = require("socket.http")
local json = require("vendor.json")
local weatherURL = 'https://openweathermap.org/data/2.5/weather?id=6695624&units=metric&appid=b6907d289e10d714a6e88b30761fae22'
local spejsiotURL = 'http://spejsiot.waw.hackerspace.pl/api/1/devices'
local atURL = 'http://at.hackerspace.pl/api'
local spejsiotData = {}
local atData = nil
local r, c, h = http.request(weatherURL)
if c == 200 then
local data = json.decode(r)
local r, c, h = http.request(spejsiotURL)
if c == 200 then
spejsiotData = json.decode(r)
end
local r, c, h = http.request(atURL)
if c == 200 then
atData = json.decode(r)
end
love.thread.getChannel('newdash'):push({
weather = data.weather[1].main:lower(),
temperature = data.main.temp,
lastUpdate = data.dt,
spejsiot = spejsiotData,
at = atData,
})
print("Update finished")
else
print("Update failed")
end