X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/32d1dda2f0bd020d68ed86125f904f286551455e..ec3604e73735e4b1f447f8dbac41d056e086505f:/widgets/yawn/init.lua?ds=sidebyside diff --git a/widgets/yawn/init.lua b/widgets/yawn/init.lua index 2306fed..3f08cd5 100644 --- a/widgets/yawn/init.lua +++ b/widgets/yawn/init.lua @@ -47,8 +47,7 @@ yawn_notification_preset = {} local function fetch_weather() local url = api_url .. units_set .. city_id - local f = io.popen("curl --connect-timeout 1 -fsm 1 '" - .. url .. "'" ) + local f = io.popen("curl --connect-timeout 1 -fsm 3 '" .. url .. "'" ) local text = f:read("*all") f:close() @@ -59,19 +58,27 @@ local function fetch_weather() yawn.icon:set_image(icon_path .. "na.png") if text == "" then weather_data = "Service not available at the moment." - yawn.widget:set_text("N/A") + yawn.widget:set_text(" N/A ") else weather_data = "City not found!\n" .. "Are you sure " .. city_id .. " is your Yahoo city ID?" - yawn.widget:set_text("?") + yawn.widget:set_text(" ? ") end return end -- Processing raw data weather_data = text:gsub("<.->", "") - weather_data = weather_data:match("Current Conditions:.-Full") + weather_data = weather_data:match("Current Conditions:.-Full") or "" + + -- may still happens in case of bad connectivity + if weather_data == "" then + yawn.icon:set_image(icon_path .. "na.png") + yawn.widget:set_text(" ? ") + return + end + weather_data = weather_data:gsub("Current Conditions:.-\n", "Now: ") weather_data = weather_data:gsub("Forecast:.-\n", "") weather_data = weather_data:gsub("\nFull", "") @@ -107,11 +114,8 @@ local function fetch_weather() sky = sky .. forecast:gsub(" ", ""):gsub("/", "") .. ".png" -- In case there's no defined icon for current forecast - f = io.popen(sky) - if f == nil then + if io.open(sky) == nil then sky = icon_path .. "na.png" - else - io.close(f) end -- Localization @@ -145,7 +149,7 @@ function yawn.hide() end function yawn.show(t_out) - if yawn.widget._layout.text == "?" + if yawn.widget._layout.text:match("?") then fetch_weather(settings) end