-
Notifications
You must be signed in to change notification settings - Fork 6
/
weather.lua
50 lines (46 loc) · 1.61 KB
/
weather.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require "color_support"
-- from https://stackoverflow.com/questions/59561776/how-do-i-insert-a-string-into-another-string-in-lua
function string.insert(str1, str2, pos)
return str1:sub(1,pos)..str2..str1:sub(pos+1)
end
local function weatherButtonForLocation(location)
return {
['name'] = 'Weather',
['imageProvider'] = function()
local url = "wttr.in?format=1"
if location ~= nil then
url = "wttr.in/" .. location
url = url .. "?format=1"
end
local command = 'curl --max-time 0.5 --silent ' .. url
command = command .. '| sed "s/+//" | sed "s/F//" | grep -v "Unknow"'
local output = hs.execute(command)
local fontSize = 40
if location ~= nil then
output = location .. '\n' .. output
fontSize = 24
end
local options = {
['fontSize'] = fontSize,
['textColor'] = systemTextColor
}
return streamdeck_imageFromText(output, options)
end,
['updateInterval'] = 1800,
}
end
function weatherButton()
local button = weatherButtonForLocation(nil)
button['children'] = function()
return {
weatherButtonForLocation('LA'),
weatherButtonForLocation('NYC'),
weatherButtonForLocation('Denver'),
weatherButtonForLocation('MN'),
weatherButtonForLocation('London'),
weatherButtonForLocation('Sydney'),
weatherButtonForLocation('Honolulu')
}
end
return button
end