Add weather last update, room temperature and date

master
informatic 2017-01-08 02:02:59 +01:00
parent ecb46842ae
commit c65f888bef
3 changed files with 32 additions and 14 deletions

View File

@ -2,6 +2,7 @@ local node = {}
local socket = require("socket")
local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 400)
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 60)
function node.load()
end
@ -11,8 +12,12 @@ function node.render()
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.setColor( 255, 255, 255 )
love.graphics.setFont(textFont);
love.graphics.printf(os.date('%H:%M'), 0, 120, love.graphics.getWidth(), 'center');
love.graphics.setFont(smallFont);
love.graphics.printf(os.date('%Y/%m/%d'), 0, 575, love.graphics.getWidth(), 'center');
end
function node.update(dt)

View File

@ -4,7 +4,7 @@ local inspect = require('vendor.inspect')
local weatherFont = love.graphics.newFont('fonts/weathericons-regular-webfont.ttf', 400)
local textFont = love.graphics.newFont('fonts/Lato-Thin.ttf', 300)
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 20)
local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
local weatherGlyphs = {
snow = "",
@ -13,10 +13,7 @@ local weatherGlyphs = {
local updateInterval = 60
local lastUpdate = 0
local state = {
weather = "snow",
temperature = 0,
}
local state = nil
function node.load()
end
@ -30,14 +27,19 @@ function node.render()
love.graphics.setColor( 255, 255, 255 )
love.graphics.setFont(textFont);
love.graphics.printf(tostring(state.temperature) .. "°", 600, 180, 650, 'center');
if state then
love.graphics.setFont(weatherFont)
love.graphics.print(tostring(weatherGlyphs[state.weather]), 150, 0)
love.graphics.setFont(weatherFont);
love.graphics.print(tostring(weatherGlyphs[state.weather]), 150, 0);
love.graphics.setFont(textFont)
love.graphics.printf(tostring(state.temperature) .. "°", 600, 180, 650, 'center')
love.graphics.setFont(smallFont)
love.graphics.printf("piździ x---DD", 0, love.graphics.getHeight() - 40, love.graphics.getWidth(), 'center')
love.graphics.setFont(smallFont)
love.graphics.printf(os.date("Last update: %Y/%m/%d %H:%M", state.lastUpdate), 0, love.graphics.getHeight() - 60, love.graphics.getWidth(), 'center')
if state.insideTemperature then
love.graphics.printf("Room: " .. state.insideTemperature .. "° / " .. state.insideHumidity .. "%RH", 0, love.graphics.getHeight() - 100, love.graphics.getWidth(), 'center')
end
end
end
function node.update(dt)

View File

@ -1,17 +1,28 @@
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 insideURL = 'http://dht01.waw.hackerspace.pl/'
local insideData = {}
local r, c, h = http.request(weatherURL)
if c == 200 then
local data = json.decode(r)
print(inspect(data), data.main.temp)
local r, c, h = http.request(insideURL)
if c == 200 then
for n in string.gmatch(string.gsub(r, ",", "."), ":(%S+)[*%%]") do
insideData[#insideData+1] = n
end
end
love.thread.getChannel('weather'):push({
weather = data.weather[1].main:lower(),
temperature = data.main.temp,
lastUpdate = data.dt,
insideTemperature = insideData[1],
insideHumidity = insideData[2],
})
else
print("failed")