diff options
author | streetturtle <streetturtle@users.noreply.github.com> | 2018-03-24 20:53:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-24 20:53:44 -0400 |
commit | d46954629f14a9d4cebd18ac7b25046282487f97 (patch) | |
tree | 65ea4e4e73437783f4399aee8ea376a59b96cefb | |
parent | 74f3d82bddcfd36b92faa6fdfdd34863537a2c70 (diff) | |
parent | 77b50a21e64652369b9ce414b2a13e2c51d3d576 (diff) |
Merge pull request #38 from webknjaz/feature/support-weather-city-key-change-via-env
Support weather city key change via env vars
-rw-r--r-- | weather-widget/weather.lua | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index 07863dd..43ce974 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 { @@ -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] @@ -97,7 +100,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] @@ -114,12 +117,12 @@ weather_widget:connect_signal("mouse::enter", function() icon = path_to_icons .. icon_map[resp.weather[1].icon], icon_size=20, text = - '<big>' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')</big><br>' .. - '<b>Humidity:</b> ' .. resp.main.humidity .. '%<br>' .. - '<b>Temperature: </b>' .. to_celcius(resp.main.temp) .. '<br>' .. - '<b>Pressure: </b>' .. resp.main.pressure .. 'hPa<br>' .. - '<b>Clouds: </b>' .. resp.clouds.all .. '%<br>' .. - '<b>Wind: </b>' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')', + '<big>' .. resp.weather[1].main .. ' (' .. resp.weather[1].description .. ')</big><br>' .. + '<b>Humidity:</b> ' .. resp.main.humidity .. '%<br>' .. + '<b>Temperature: </b>' .. to_celcius(resp.main.temp) .. '<br>' .. + '<b>Pressure: </b>' .. resp.main.pressure .. 'hPa<br>' .. + '<b>Clouds: </b>' .. resp.clouds.all .. '%<br>' .. + '<b>Wind: </b>' .. resp.wind.speed .. 'm/s (' .. to_direction(resp.wind.deg) .. ')', timeout = 5, hover_timeout = 10, width = 200 } |