diff options
author | streetturtle <streetturtle@users.noreply.github.com> | 2019-09-19 09:56:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-19 09:56:23 -0400 |
commit | 3b15540c2a4c95e3b28039a8a2929c628d2e1e98 (patch) | |
tree | da382aceb80528235f4f8f88f3cc580389dfb0f8 /weather-widget/weather.lua | |
parent | 2f20cc54c792c38f52072e2f6afb92eb6e1421ec (diff) | |
parent | e154daa8b67b0e10b9615ef68852fab1f8ec29bb (diff) |
Merge pull request #96 from utix/weather_error
Weather improve error catching and add position option
Diffstat (limited to 'weather-widget/weather.lua')
-rw-r--r-- | weather-widget/weather.lua | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index b0aa070..9befd6b 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -28,6 +28,7 @@ local function worker(args) local units = args.units or 'metric' local both_units_widget = args.both_units_widget or false local both_units_popup = args.both_units_popup or false + local position = args.notification_position or "top_right" local weather_api_url = ( 'https://api.openweathermap.org/data/2.5/weather' @@ -142,6 +143,15 @@ local function worker(args) return s end + local function error_display(resp_json) + local err_resp = json.decode(resp_json) + naughty.notify{ + title = 'Weather Widget Error', + text = err_resp.message, + preset = naughty.config.presets.critical, + } + end + weather_timer:connect_signal("timeout", function () local resp_json = {} local res, status = http.request{ @@ -164,12 +174,13 @@ local function worker(args) end if (status ~= 200 and resp_json ~= nil and resp_json ~= '') then - local err_resp = json.decode(resp_json) - naughty.notify{ - title = 'Weather Widget Error', - text = err_resp.message, - preset = naughty.config.presets.critical, - } + if (not pcall(error_display, resp_json)) then + naughty.notify{ + title = 'Weather Widget Error', + text = 'Cannot parse answer', + preset = naughty.config.presets.critical, + } + end elseif (resp_json ~= nil and resp_json ~= '') then resp = json.decode(resp_json) icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon] @@ -194,6 +205,7 @@ local function worker(args) '<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, + position = position, width = (both_units_popup == true and 210 or 200) } end) |