From f4b18c6f82073b96bb339112ca00c3241bd600c4 Mon Sep 17 00:00:00 2001 From: elenapan Date: Wed, 1 Apr 2020 14:37:22 +0300 Subject: [PATCH] Improve weather and corona daemons They now remove the temp_file when the output of the command is not valid in order to force an update the next time a check is made. --- config/awesome/evil/coronavirus.lua | 12 ++++++++++-- config/awesome/evil/weather.lua | 5 ++++- config/awesome/rc.lua | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/config/awesome/evil/coronavirus.lua b/config/awesome/evil/coronavirus.lua index 76876db..c48e542 100644 --- a/config/awesome/evil/coronavirus.lua +++ b/config/awesome/evil/coronavirus.lua @@ -10,6 +10,7 @@ local naughty = require("naughty") local update_interval = 60 * 60 * 12 -- 12 hours local country = user.coronavirus_country or "usa" +local temp_file = "/tmp/awesomewm-evil-coronavirus" local coronavirus_script = [[ sh -c ' @@ -25,11 +26,18 @@ local coronavirus_script = [[ echo CTOTAL@$cases_total@CTODAY@$cases_today@DTOTAL@$deaths_total@DTODAY@$deaths_today@ ']] -helpers.remote_watch(coronavirus_script, update_interval, "/tmp/awesomewm-evil-coronavirus", function(stdout) +helpers.remote_watch(coronavirus_script, update_interval, temp_file, function(stdout) local cases_total = stdout:match('^CTOTAL@(.*)@CTODAY') local cases_today = stdout:match('CTODAY@(.*)@DTOTAL') local deaths_total = stdout:match('DTOTAL@(.*)@DTODAY') local deaths_today = stdout:match('DTODAY@(.*)@') - awesome.emit_signal("evil::coronavirus", cases_total, cases_today, deaths_total, deaths_today) + -- If it is found, we assume the command succeeded + if cases_total then + awesome.emit_signal("evil::coronavirus", cases_total, cases_today, deaths_total, deaths_today) + else + -- Remove temp_file to force an update the next time + awful.spawn.with_shell("rm "..temp_file) + awesome.emit_signal("evil::coronavirus", -1, -1, -1, -1) + end end) diff --git a/config/awesome/evil/weather.lua b/config/awesome/evil/weather.lua index 4189327..c3a184a 100644 --- a/config/awesome/evil/weather.lua +++ b/config/awesome/evil/weather.lua @@ -12,6 +12,7 @@ local city_id = user.openweathermap_city_id local units = user.weather_units -- Don't update too often, because your requests might get blocked for 24 hours local update_interval = 1200 +local temp_file = "/tmp/awesomewm-evil-weather" local weather_details_script = [[ bash -c ' @@ -32,7 +33,7 @@ local weather_details_script = [[ fi ']] -helpers.remote_watch(weather_details_script, update_interval, "/tmp/awesomewm-evil-weather", function(stdout) +helpers.remote_watch(weather_details_script, update_interval, temp_file, function(stdout) local icon_code = string.sub(stdout, 1, 3) local weather_details = string.sub(stdout, 5) weather_details = string.gsub(weather_details, '^%s*(.-)%s*$', '%1') @@ -43,6 +44,8 @@ helpers.remote_watch(weather_details_script, update_interval, "/tmp/awesomewm-ev local description = weather_details:match('(.*)@@') local temperature = weather_details:match('@@(.*)') if icon_code == "..." then + -- Remove temp_file to force an update the next time + awful.spawn.with_shell("rm "..temp_file) awesome.emit_signal("evil::weather", 999, "Weather unavailable", "") else awesome.emit_signal("evil::weather", tonumber(temperature), description, icon_code) diff --git a/config/awesome/rc.lua b/config/awesome/rc.lua index beac87b..977ecc8 100644 --- a/config/awesome/rc.lua +++ b/config/awesome/rc.lua @@ -130,7 +130,7 @@ user = { -- >> Coronavirus << -- Country to check for corona statistics -- Uses the https://corona-stats.online API - coronavirus_country = "usa", + coronavirus_country = "germany", } -- ===================================================================