2023-05-16 08:43:03 +00:00
|
|
|
#!/usr/bin/env lua
|
|
|
|
|
2023-05-16 12:13:13 +00:00
|
|
|
local json = require "cjson"
|
|
|
|
local arrr = require "arrr"
|
|
|
|
local shapeshift = require "shapeshift"
|
2023-05-16 08:43:03 +00:00
|
|
|
|
|
|
|
local function zulu_offset()
|
|
|
|
local current = os.date("*t")
|
|
|
|
current.isdst = false
|
|
|
|
local zulu = os.date("!*t")
|
|
|
|
return os.difftime(os.time(current), os.time(zulu))
|
|
|
|
end
|
|
|
|
|
|
|
|
local params do
|
|
|
|
local parse = arrr {
|
2023-05-16 12:13:13 +00:00
|
|
|
{ "Time or something", "--minutes", "-m", "number" };
|
|
|
|
{ "Use Zenity to display a window instead of sending a notification", "--zenity", "-z" }
|
2023-05-16 08:43:03 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 12:13:13 +00:00
|
|
|
local validate = shapeshift.table {
|
|
|
|
__extra = "keep";
|
|
|
|
minutes = shapeshift.default(30, shapeshift.is.number);
|
|
|
|
}
|
2023-05-16 08:43:03 +00:00
|
|
|
|
2023-05-16 12:13:13 +00:00
|
|
|
params = select(2, validate(parse(arg)))
|
2023-05-16 08:43:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local done = {}
|
|
|
|
|
|
|
|
while true do
|
|
|
|
local data = json.decode(io.popen("task export"):read("*a"))
|
|
|
|
for _, task in ipairs(data) do
|
|
|
|
if task.status == "pending" and task.due then
|
2023-05-16 12:13:13 +00:00
|
|
|
do
|
2023-05-16 08:43:03 +00:00
|
|
|
local d = {}
|
|
|
|
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")
|
|
|
|
d.sec = d.sec + zulu_offset()
|
2023-05-16 12:13:13 +00:00
|
|
|
task.due = os.time(d)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- 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
|
2023-05-16 08:43:03 +00:00
|
|
|
end
|
|
|
|
|
2023-05-16 12:13:13 +00:00
|
|
|
if os.difftime(task.due, os.time()) < 60*params.minutes then
|
2023-05-16 08:43:03 +00:00
|
|
|
if not done[task.uuid] then
|
|
|
|
done[task.uuid] = task
|
|
|
|
print("Notifying:", task.uuid, task.description)
|
2023-05-16 12:13:13 +00:00
|
|
|
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([[']], [['"'"']]).."'")
|
|
|
|
end
|
2023-05-16 08:43:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-16 12:13:13 +00:00
|
|
|
if not os.execute("sleep 5") then
|
2023-05-16 08:43:03 +00:00
|
|
|
os.exit()
|
|
|
|
end
|
|
|
|
end
|