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 insideURL = 'https://dht01.waw.hackerspace.pl/' |
| 7 | --local insideData = {} |
| 8 | |
| 9 | local c, r, h = https.request(weatherURL) |
| 10 | if c == 200 then |
| 11 | local data = json.decode(r) |
| 12 | |
| 13 | --local r, c, h = http.request(insideURL) |
| 14 | --if c == 200 then |
| 15 | -- for n in string.gmatch(string.gsub(r, ",", "."), ":%s*(%S+)[*%%]") do |
| 16 | -- insideData[#insideData+1] = n |
| 17 | -- end |
| 18 | --end |
| 19 | |
| 20 | love.thread.getChannel('weather'):push({ |
| 21 | weather = data.weather[1].main:lower(), |
| 22 | temperature = data.main.temp, |
| 23 | lastUpdate = data.dt, |
| 24 | sunRise = data.sys.sunrise, |
| 25 | sunSet = data.sys.sunset, |
| 26 | insideTemperature = nil, |
| 27 | insideHumidity = nil, |
| 28 | }) |
| 29 | print("Update finished") |
| 30 | else |
| 31 | print("Update failed") |
| 32 | end |