From 2961e60b0edfe7ec34376d7d3ce5d74e074d70c6 Mon Sep 17 00:00:00 2001 From: elenapan Date: Wed, 1 Apr 2020 09:04:54 +0300 Subject: [PATCH] Add evil coronavirus daemon --- config/awesome/evil/coronavirus.lua | 35 +++++++++++++++++++++++++++++ config/awesome/evil/init.lua | 1 + config/awesome/rc.lua | 5 +++++ 3 files changed, 41 insertions(+) create mode 100644 config/awesome/evil/coronavirus.lua diff --git a/config/awesome/evil/coronavirus.lua b/config/awesome/evil/coronavirus.lua new file mode 100644 index 0000000..76876db --- /dev/null +++ b/config/awesome/evil/coronavirus.lua @@ -0,0 +1,35 @@ +-- Provides: +-- evil::coronavirus +-- cases_total (integer) +-- cases_today (integer) +-- deaths_total (integer) +-- deaths_today (integer) +local awful = require("awful") +local helpers = require("helpers") +local naughty = require("naughty") + +local update_interval = 60 * 60 * 12 -- 12 hours +local country = user.coronavirus_country or "usa" + +local coronavirus_script = [[ + sh -c ' + country="]]..country..[[" + + stats=$(curl "https://corona-stats.online/$country?format=json" 2>/dev/null) + + cases_total="$(echo $stats | jq ".data[0].cases")" + cases_today="$(echo $stats | jq ".data[0].todayCases")" + deaths_total="$(echo $stats | jq ".data[0].deaths")" + deaths_today="$(echo $stats | jq ".data[0].todayDeaths")" + + 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) + 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) +end) diff --git a/config/awesome/evil/init.lua b/config/awesome/evil/init.lua index 2135d0e..6f3ac13 100644 --- a/config/awesome/evil/init.lua +++ b/config/awesome/evil/init.lua @@ -12,4 +12,5 @@ require("evil.brightness") -- require("evil.spotify") -- Internet access required +require("evil.coronavirus") require("evil.weather") diff --git a/config/awesome/rc.lua b/config/awesome/rc.lua index 2889782..bddc560 100644 --- a/config/awesome/rc.lua +++ b/config/awesome/rc.lua @@ -120,6 +120,11 @@ user = { openweathermap_city_id = "yyyyyy", -- > Use "metric" for Celcius, "imperial" for Fahrenheit weather_units = "metric", + + -- >> Coronavirus << + -- Country to check for corona statistics + -- Uses the https://corona-stats.online API + coronavirus_country = "usa", } -- ===================================================================