aboutsummaryrefslogtreecommitdiff
path: root/contrib/rss.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-08-29 00:49:57 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-08-29 00:49:57 +0200
commit26b0395ba988948a7cc8b79d08faf6a57058886a (patch)
treeae475623e8b249aa8b8d29b57878737f09c165f5 /contrib/rss.lua
parent0d6333ed61a305c8a18fd4eb42ad33a353627bc9 (diff)
downloadvicious-legacy-26b0395ba988948a7cc8b79d08faf6a57058886a.tar.xz
contrib: imported contrib widgets
Diffstat (limited to 'contrib/rss.lua')
-rw-r--r--contrib/rss.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/contrib/rss.lua b/contrib/rss.lua
new file mode 100644
index 0000000..bba1bf2
--- /dev/null
+++ b/contrib/rss.lua
@@ -0,0 +1,67 @@
+---------------------------------------------------
+-- Licensed under the GNU General Public License v2
+-- * (c) 2009, olcc
+--
+-- This is now a standalone RSS reader for awesome:
+-- * http://github.com/olcc/aware
+---------------------------------------------------
+
+-- {{{ Grab environment
+local pairs = pairs
+local io = { popen = io.popen }
+local setmetatable = setmetatable
+-- }}}
+
+
+-- RSS: provides latest world news
+module("vicious.contrib.rss")
+
+
+-- {{{ RSS widget type
+local function worker(format, input)
+ -- input: * feed - feed url
+ -- * object - entity to look for (typically: 'item')
+ -- * fields - fields to read (example: 'link', 'title', 'description')
+ -- output: * count - number of entities found
+ -- * one table for each field, containing wanted values
+ local feed = input.feed
+ local object = input.object
+ local fields = input.fields
+
+ -- Initialise tables
+ local out = {}
+
+ for _, v in pairs(fields) do
+ out[v] = {}
+ end
+
+ -- Initialise variables
+ local ob = nil
+ local i,j,k = 1, 1, 0
+ local curl = "curl -A 'Mozilla/4.0' -fsm 5 --connect-timeout 3 "
+
+ -- Get the feed
+ local f = io.popen(curl .. '"' .. feed .. '"')
+ local feed = f:read("*all")
+ f:close()
+
+ while true do
+ i, j, ob = feed.find(feed, "<" .. object .. ">(.-)</" .. object .. ">", i)
+ if not ob then break end
+
+ for _, v in pairs(fields) do
+ out[v][k] = ob:match("<" .. v .. ">(.*)</" .. v .. ">")
+ end
+
+ k = k+1
+ i = j+1
+ end
+
+ -- Update the entity count
+ out.count = k
+
+ return out
+end
+-- }}}
+
+setmetatable(_M, { __call = function(_, ...) return worker(...) end })