summaryrefslogtreecommitdiffstats
path: root/screens/weather_thread.lua
blob: 7638c9a8c09a8fa01e897754fd6df6a3f41d0fe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
local socket = require("socket")
local http = require("socket.http")
local json = require("vendor.json")
local inspect = require('vendor.inspect')
-- local weatherURL = 'http://api.wunderground.com/api/0def10027afaebb7/conditions/q/PL/Warszawa.json'
local weatherURL = 'https://openweathermap.org/data/2.5/weather?id=6695624&units=metric&appid=b1b15e88fa797225412429c1c50c122a1'

local r, c, h = http.request(weatherURL)
if c == 200 then
  local data = json.decode(r)
  print(inspect(data), data.main.temp)
  love.thread.getChannel('weather'):push({
    weather = data.weather[1].main:lower(),
    temperature = data.main.temp,
  })
else
  print("failed")
end