blob: 5585e150cefaf18c4988005104b824fa69c0092f [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'
6--local insideURL = 'https://dht01.waw.hackerspace.pl/'
7--local insideData = {}
8
9local c, r, h = https.request(weatherURL)
10if 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")
30else
31 print("Update failed")
32end