Serge Bazanski | 18c1a26 | 2022-07-07 14:24:53 +0200 | [diff] [blame] | 1 | local socket = require("socket") |
| 2 | local https = require("https") |
| 3 | local json = require("vendor.json") |
| 4 | |
| 5 | local weatherURL = 'https://openweathermap.org/data/2.5/weather?id=6695624&units=metric&appid=439d4b804bc8187953eb36d2a8c26a02' |
| 6 | local spejsiotURL = 'https://spejsiot.waw.hackerspace.pl/api/1/devices' |
| 7 | local atURL = 'https://at.hackerspace.pl/api' |
| 8 | local spejsiotData = {} |
| 9 | local atData = nil |
| 10 | |
| 11 | local c, r, h = https.request(weatherURL) |
| 12 | if 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") |
| 34 | else |
| 35 | print("Update failed") |
| 36 | end |