From 5a5c9eb8f0bfedbc96a8e82f765d686267f5d5ce Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 21 Mar 2018 19:16:43 +0100 Subject: Read city and api key from env first Corresponding env vars are: * AWW_WEATHER_CITY * AWW_WEATHER_API_KEY --- weather-widget/weather.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'weather-widget/weather.lua') diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index 07863dd..c8b1358 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -11,8 +11,8 @@ local json = require("json") local naughty = require("naughty") local wibox = require("wibox") -local city = "Montreal,ca" -local open_map_key = 'c3d7320b359da4e48c2d682a04076576' +local city = os.getenv("AWW_WEATHER_CITY") or "Montreal,ca" +local open_map_key = os.getenv("AWW_WEATHER_API_KEY") or 'c3d7320b359da4e48c2d682a04076576' local path_to_icons = "/usr/share/icons/Arc/status/symbolic/" local icon_widget = wibox.widget { -- cgit v1.2.3 From 1381ea5275092dd5e0c40c7aa403cc669910ca13 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 21 Mar 2018 19:17:56 +0100 Subject: Access weather API via HTTPS --- weather-widget/weather.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'weather-widget/weather.lua') diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index c8b1358..463c785 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -97,7 +97,7 @@ local weather_timer = timer({ timeout = 60 }) local resp weather_timer:connect_signal("timeout", function () - local resp_json = http.request("http://api.openweathermap.org/data/2.5/weather?q=" .. city .."&appid=" .. open_map_key) + local resp_json = http.request("https://api.openweathermap.org/data/2.5/weather?q=" .. city .."&appid=" .. open_map_key) if (resp_json ~= nil) then resp = json.decode(resp_json) icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon] -- cgit v1.2.3 From 2e12e47eb1176e752d7be381b877d65f24c4087d Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 21 Mar 2018 19:18:11 +0100 Subject: Beautify pop-up code style --- weather-widget/weather.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'weather-widget/weather.lua') diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index 463c785..854ff49 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -114,12 +114,12 @@ weather_widget:connect_signal("mouse::enter", function() icon = path_to_icons .. icon_map[resp.weather[1].icon], icon_size=20, text = - '' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')
' .. - 'Humidity: ' .. resp.main.humidity .. '%
' .. - 'Temperature: ' .. to_celcius(resp.main.temp) .. '
' .. - 'Pressure: ' .. resp.main.pressure .. 'hPa
' .. - 'Clouds: ' .. resp.clouds.all .. '%
' .. - 'Wind: ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')', + '' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')
' .. + 'Humidity: ' .. resp.main.humidity .. '%
' .. + 'Temperature: ' .. to_celcius(resp.main.temp) .. '
' .. + 'Pressure: ' .. resp.main.pressure .. 'hPa
' .. + 'Clouds: ' .. resp.clouds.all .. '%
' .. + 'Wind: ' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')', timeout = 5, hover_timeout = 10, width = 200 } -- cgit v1.2.3 From 77b50a21e64652369b9ce414b2a13e2c51d3d576 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Thu, 22 Mar 2018 09:46:46 +0100 Subject: Take into account case with an unset wind degrees Fixes exception, which happens when comparing nil to a number --- weather-widget/weather.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'weather-widget/weather.lua') diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index 854ff49..43ce974 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -86,6 +86,9 @@ function to_direction(degrees) { "NW", 303.75, 326.25 }, { "NNW", 326.25, 348.75 }, } + if degrees == nil then + return "Unknown dir" + end for i, dir in ipairs(directions) do if degrees > dir[2] and degrees < dir[3] then return dir[1] -- cgit v1.2.3