Improve task notifier
This commit is contained in:
parent
f14c797b96
commit
72451ccc12
1 changed files with 27 additions and 13 deletions
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env lua
|
#!/usr/bin/env lua
|
||||||
|
|
||||||
local json = require 'cjson'
|
local json = require "cjson"
|
||||||
local arrr = require 'arrr'
|
local arrr = require "arrr"
|
||||||
local inspect = require "inspect"
|
local shapeshift = require "shapeshift"
|
||||||
|
|
||||||
local function zulu_offset()
|
local function zulu_offset()
|
||||||
local current = os.date("*t")
|
local current = os.date("*t")
|
||||||
|
@ -13,14 +13,16 @@ end
|
||||||
|
|
||||||
local params do
|
local params do
|
||||||
local parse = arrr {
|
local parse = arrr {
|
||||||
{ "Time or something", "--time", "-t", "time" };
|
{ "Time or something", "--minutes", "-m", "number" };
|
||||||
|
{ "Use Zenity to display a window instead of sending a notification", "--zenity", "-z" }
|
||||||
}
|
}
|
||||||
|
|
||||||
local function validate(args)
|
local validate = shapeshift.table {
|
||||||
return args
|
__extra = "keep";
|
||||||
end
|
minutes = shapeshift.default(30, shapeshift.is.number);
|
||||||
|
}
|
||||||
|
|
||||||
params = validate(parse(arg))
|
params = select(2, validate(parse(arg)))
|
||||||
end
|
end
|
||||||
|
|
||||||
local done = {}
|
local done = {}
|
||||||
|
@ -29,25 +31,37 @@ while true do
|
||||||
local data = json.decode(io.popen("task export"):read("*a"))
|
local data = json.decode(io.popen("task export"):read("*a"))
|
||||||
for _, task in ipairs(data) do
|
for _, task in ipairs(data) do
|
||||||
if task.status == "pending" and task.due then
|
if task.status == "pending" and task.due then
|
||||||
local due do
|
do
|
||||||
local d = {}
|
local d = {}
|
||||||
d.year, d.month, d.day, d.hour, d.min, d.sec
|
d.year, d.month, d.day, d.hour, d.min, d.sec
|
||||||
= task.due:match("(%d%d%d%d)(%d%d)(%d%d)T(%d%d)(%d%d)(%d%d)Z")
|
= task.due:match("(%d%d%d%d)(%d%d)(%d%d)T(%d%d)(%d%d)(%d%d)Z")
|
||||||
d.sec = d.sec + zulu_offset()
|
d.sec = d.sec + zulu_offset()
|
||||||
due = os.time(d)
|
task.due = os.time(d)
|
||||||
end
|
end
|
||||||
|
|
||||||
if os.difftime(due, os.time()) < 3600*params.time then
|
-- If anything gets postponed outside of the warning time,
|
||||||
|
-- remove it from the done list
|
||||||
|
if done[task.uuid] then
|
||||||
|
if os.difftime(task.due, os.time()) > 60*params.minutes then
|
||||||
|
done[task.uuid] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if os.difftime(task.due, os.time()) < 60*params.minutes then
|
||||||
if not done[task.uuid] then
|
if not done[task.uuid] then
|
||||||
done[task.uuid] = task
|
done[task.uuid] = task
|
||||||
print("Notifying:", task.uuid, task.description)
|
print("Notifying:", task.uuid, task.description)
|
||||||
|
if params.zenity then
|
||||||
|
os.execute(string.format("zenity --warning --title '%s' --text '%s'", "Task due soon", task.description))
|
||||||
|
else
|
||||||
os.execute("notify-send 'Task due soon' '"..task.description:gsub([[']], [['"'"']]).."'")
|
os.execute("notify-send 'Task due soon' '"..task.description:gsub([[']], [['"'"']]).."'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not os.execute("sleep 3") then
|
if not os.execute("sleep 5") then
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue