blob: ab256e53c7dced08f778720d088d6a849a32ed91 [file] [log] [blame]
Serge Bazanski18c1a262022-07-07 14:24:53 +02001local socket = require("socket")
2local https = require("https")
3local json = require("vendor.json")
4
5local weatherURL = 'https://openweathermap.org/data/2.5/weather?id=6695624&units=metric&appid=439d4b804bc8187953eb36d2a8c26a02'
6local spejsiotURL = 'https://spejsiot.waw.hackerspace.pl/api/1/devices'
7local atURL = 'https://at.hackerspace.pl/api'
8local spejsiotData = {}
9local atData = nil
10
11local c, r, h = https.request(weatherURL)
12if c == 200 then
13 local data = json.decode(r)
14
15 local c, r, h = https.request(spejsiotURL)
16 if c == 200 then
17 spejsiotData = json.decode(r)
18 end
19
20 local c, r, h = https.request(atURL)
21
22 if c == 200 then
23 atData = json.decode(r)
24 end
25
26 love.thread.getChannel('newdash'):push({
27 weather = data.weather[1].main:lower(),
28 temperature = data.main.temp,
29 lastUpdate = data.dt,
30 spejsiot = spejsiotData,
31 at = atData,
32 })
33 print("Update finished")
34else
35 print("Update failed")
36end