summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-01-08 13:54:01 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2017-01-08 13:54:01 +0100
commit1496814f1b399e7dde97fb4e0da3f7a463bded03 (patch)
tree06df5514be9fcdaa2d427b5bb51fc2e0f1172de2
parentc65f888befe74e30136a24dad240e1f0c8ac9fc6 (diff)
downloadlove2d-signage-1496814f1b399e7dde97fb4e0da3f7a463bded03.tar.gz
love2d-signage-1496814f1b399e7dde97fb4e0da3f7a463bded03.tar.bz2
love2d-signage-1496814f1b399e7dde97fb4e0da3f7a463bded03.zip
Add misery module, fix unknown weather icon
-rw-r--r--main.lua1
-rw-r--r--screens/misery.lua50
-rw-r--r--screens/misery_thread.lua35
-rw-r--r--screens/weather.lua22
-rw-r--r--screens/weather_thread.lua3
5 files changed, 103 insertions, 8 deletions
diff --git a/main.lua b/main.lua
index c9f63fb..69458c2 100644
--- a/main.lua
+++ b/main.lua
@@ -7,6 +7,7 @@ environment = os.getenv('ENV')
screens = {
require 'screens.weather',
require 'screens.time',
+ require 'screens.misery',
require 'screens.screen1',
}
diff --git a/screens/misery.lua b/screens/misery.lua
new file mode 100644
index 0000000..e4d6258
--- /dev/null
+++ b/screens/misery.lua
@@ -0,0 +1,50 @@
+local node = {}
+
+local inspect = require('vendor.inspect')
+
+local textFont = love.graphics.newFont('fonts/Lato-Light.ttf', 50)
+local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
+
+local updateInterval = 2 * 60
+local lastUpdate = 0
+local state = nil
+
+function node.load()
+end
+
+function node.unload()
+end
+
+function node.render()
+ love.graphics.setColor( 0, 0, 0 )
+ love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
+
+ if state then
+ love.graphics.setColor( 255, 255, 255 )
+ love.graphics.setFont(textFont)
+ love.graphics.printf(state.text, 50, 180, love.graphics.getWidth() - 100, 'center')
+
+ love.graphics.setColor( 255, 255, 255, 200 )
+ love.graphics.setFont(smallFont)
+ love.graphics.printf(state.description, 200, love.graphics.getHeight() - 100, love.graphics.getWidth() - 400, 'center')
+ else
+ love.graphics.setColor( 255, 255, 255, 80 )
+
+ love.graphics.setFont(smallFont)
+ love.graphics.printf("Loading misery...", 0, love.graphics.getHeight() - 200, love.graphics.getWidth(), 'center')
+ end
+end
+
+function node.update(dt)
+ if lastUpdate < love.timer.getTime() - updateInterval then
+ lastUpdate = love.timer.getTime()
+ print("Updating...")
+
+ local updateThread = love.thread.newThread('screens/misery_thread.lua')
+ updateThread:start()
+ end
+
+ state = love.thread.getChannel('misery'):pop() or state
+end
+
+return node
diff --git a/screens/misery_thread.lua b/screens/misery_thread.lua
new file mode 100644
index 0000000..8b0c6d9
--- /dev/null
+++ b/screens/misery_thread.lua
@@ -0,0 +1,35 @@
+local socket = require("socket")
+local http = require("socket.http")
+local json = require("vendor.json")
+local lume = require("vendor.lume")
+
+local miseryURL = 'http://oodviewer.q3k.me/term/_,'
+
+math.randomseed( os.time() )
+
+function unescape(str)
+ str = string.gsub( str, '&lt;', '<' )
+ str = string.gsub( str, '&gt;', '>' )
+ str = string.gsub( str, '&quot;', '"' )
+ str = string.gsub( str, '&apos;', "'" )
+ str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
+ str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
+ str = string.gsub( str, '&amp;', '&' ) -- Be sure to do this after all others
+ return str
+end
+
+local r, c, h = http.request(miseryURL)
+if c == 200 then
+ local data = {}
+ for item, desc in string.gmatch(r, '<li>([^\n]*) <i>([^<]*)</i>') do
+ data[#data + 1] = {
+ text = unescape(item:gsub('<[^>]*>', '')),
+ description = unescape(desc),
+ }
+ end
+
+ love.thread.getChannel('misery'):push(lume.randomchoice(data))
+ print("Update finished")
+else
+ print("Update failed")
+end
diff --git a/screens/weather.lua b/screens/weather.lua
index ebaeb1b..9af7eaf 100644
--- a/screens/weather.lua
+++ b/screens/weather.lua
@@ -9,9 +9,10 @@ local smallFont = love.graphics.newFont('fonts/Lato-Light.ttf', 30)
local weatherGlyphs = {
snow = "",
mist = "",
+ clear = "",
}
-local updateInterval = 60
+local updateInterval = 5 * 60
local lastUpdate = 0
local state = nil
@@ -25,11 +26,13 @@ function node.render()
love.graphics.setColor( 0, 0, 0 )
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
- love.graphics.setColor( 255, 255, 255 )
-
if state then
- love.graphics.setFont(weatherFont)
- love.graphics.print(tostring(weatherGlyphs[state.weather]), 150, 0)
+ love.graphics.setColor( 255, 255, 255 )
+
+ if weatherGlyphs[state.weather] then
+ love.graphics.setFont(weatherFont)
+ love.graphics.print(weatherGlyphs[state.weather], 150, 0)
+ end
love.graphics.setFont(textFont)
love.graphics.printf(tostring(state.temperature) .. "°", 600, 180, 650, 'center')
@@ -39,14 +42,19 @@ function node.render()
if state.insideTemperature then
love.graphics.printf("Room: " .. state.insideTemperature .. "° / " .. state.insideHumidity .. "%RH", 0, love.graphics.getHeight() - 100, love.graphics.getWidth(), 'center')
end
+ else
+ love.graphics.setColor( 255, 255, 255, 80 )
+
+ love.graphics.setFont(smallFont)
+ love.graphics.printf("Loading weather...", 0, love.graphics.getHeight() - 200, love.graphics.getWidth(), 'center')
end
end
function node.update(dt)
if lastUpdate < love.timer.getTime() - updateInterval then
lastUpdate = love.timer.getTime()
- print("update")
- print(inspect(state))
+ print("Updating...")
+
local updateThread = love.thread.newThread('screens/weather_thread.lua')
updateThread:start()
end
diff --git a/screens/weather_thread.lua b/screens/weather_thread.lua
index 4b1add6..8c3e9f4 100644
--- a/screens/weather_thread.lua
+++ b/screens/weather_thread.lua
@@ -24,6 +24,7 @@ if c == 200 then
insideTemperature = insideData[1],
insideHumidity = insideData[2],
})
+ print("Update finished")
else
- print("failed")
+ print("Update failed")
end