aboutsummaryrefslogtreecommitdiff
path: root/widgets/org.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-14 01:55:33 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-03-14 01:55:33 +0100
commit237470c8f45190b213e3a173ce6ae1a74b3e11fe (patch)
tree7f53c8144761947d4bde20715bcad34f4be0d6c0 /widgets/org.lua
parent9a82d4113a8271b7dfc7506f2b07379e3ede89a8 (diff)
downloadvicious-legacy-237470c8f45190b213e3a173ce6ae1a74b3e11fe.tar.xz
API: transform widgets namespace table to a directory
Diffstat (limited to 'widgets/org.lua')
-rw-r--r--widgets/org.lua59
1 files changed, 59 insertions, 0 deletions
diff --git a/widgets/org.lua b/widgets/org.lua
new file mode 100644
index 0000000..8764e3a
--- /dev/null
+++ b/widgets/org.lua
@@ -0,0 +1,59 @@
+---------------------------------------------------
+-- Licensed under the GNU General Public License v2
+-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
+-- * (c) org-awesome, Damien Leone
+---------------------------------------------------
+
+-- {{{ Grab environment
+local io = { lines = io.lines }
+local setmetatable = setmetatable
+local string = { find = string.find }
+local os = {
+ time = os.time,
+ date = os.date
+}
+-- }}}
+
+
+-- Org: provides agenda statistics for Emacs org-mode
+module("vicious.widgets.org")
+
+
+-- {{{ OrgMode widget type
+local function worker(format, warg)
+ -- Compute delays
+ local today = os.time{ year=os.date("%Y"), month=os.date("%m"), day=os.date("%d") }
+ local soon = today + 24 * 3600 * 3 -- 3 days ahead is close
+ local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum
+
+ -- Initialise counters
+ local count = { past = 0, today = 0, soon = 0, future = 0 }
+
+ -- Get data from agenda files
+ for i=1, #warg do
+ for line in io.lines(warg[i]) do
+ local scheduled = string.find(line, "SCHEDULED:")
+ local closed = string.find(line, "CLOSED:")
+ local deadline = string.find(line, "DEADLINE:")
+
+ if (scheduled and not closed) or (deadline and not closed) then
+ local b, e, y, m, d = string.find(line, "(%d%d%d%d)-(%d%d)-(%d%d)")
+
+ if b then
+ local t = os.time{ year = y, month = m, day = d }
+
+ if t < today then count.past = count.past + 1
+ elseif t == today then count.today = count.today + 1
+ elseif t <= soon then count.soon = count.soon + 1
+ elseif t <= future then count.future = count.future + 1
+ end
+ end
+ end
+ end
+ end
+
+ return {count.past, count.today, count.soon, count.future}
+end
+-- }}}
+
+setmetatable(_M, { __call = function(_, ...) return worker(...) end })