2017-12-01 00:21:33 -06:00
|
|
|
---------------------------------------------------
|
|
|
|
-- 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
|
|
|
|
-- vicious.contrib.rss
|
|
|
|
local rss = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ RSS widget type
|
|
|
|
local function worker(format, input)
|
2018-05-18 22:36:34 -05:00
|
|
|
-- 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
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Initialise tables
|
|
|
|
local out = {}
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
for _, v in pairs(fields) do
|
|
|
|
out[v] = {}
|
|
|
|
end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Initialise variables
|
|
|
|
local ob = nil
|
|
|
|
local i,j,k = 1, 1, 0
|
|
|
|
local curl = "curl -A 'Mozilla/4.0' -fsm 5 --connect-timeout 3 "
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Get the feed
|
|
|
|
local f = io.popen(curl .. '"' .. feed .. '"')
|
|
|
|
local feed = f:read("*all")
|
|
|
|
f:close()
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
while true do
|
|
|
|
i, j, ob = feed.find(feed, "<" .. object .. ">(.-)</" .. object .. ">", i)
|
|
|
|
if not ob then break end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
for _, v in pairs(fields) do
|
|
|
|
out[v][k] = ob:match("<" .. v .. ">(.*)</" .. v .. ">")
|
|
|
|
end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
k = k+1
|
|
|
|
i = j+1
|
|
|
|
end
|
2017-12-17 12:06:39 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
-- Update the entity count
|
|
|
|
out.count = k
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2018-05-18 22:36:34 -05:00
|
|
|
return out
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
return setmetatable(rss, { __call = function(_, ...) return worker(...) end })
|