rss.lua: second try
This commit is contained in:
parent
0d79c4ce88
commit
266c10006a
@ -1,3 +1,41 @@
|
|||||||
|
feedparser = (loadfile "./libs/feedparser.lua")()
|
||||||
|
|
||||||
|
local function unescape_for_rss(str)
|
||||||
|
-- Character encoding
|
||||||
|
str = string.gsub(str, "|", "|")
|
||||||
|
str = string.gsub(str, "‹", "‹")
|
||||||
|
str = string.gsub(str, "<", "<")
|
||||||
|
str = string.gsub(str, ">", ">")
|
||||||
|
str = string.gsub(str, "'", "'")
|
||||||
|
str = string.gsub(str, "’", "'")
|
||||||
|
str = string.gsub(str, "–", "–")
|
||||||
|
str = string.gsub(str, "»", "»")
|
||||||
|
str = string.gsub(str, "»", "»")
|
||||||
|
str = string.gsub(str, "–", "–")
|
||||||
|
str = string.gsub(str, "“", "“")
|
||||||
|
str = string.gsub(str, "”", "”")
|
||||||
|
str = string.gsub(str, "€", "€")
|
||||||
|
str = string.gsub(str, "ß", "ß")
|
||||||
|
|
||||||
|
-- Ä Ö Ü
|
||||||
|
str = string.gsub(str, "ä", "ä")
|
||||||
|
str = string.gsub(str, "Ä", "Ä")
|
||||||
|
str = string.gsub(str, "ä", "ä")
|
||||||
|
str = string.gsub(str, "Ä", "Ä")
|
||||||
|
str = string.gsub(str, "ö", "ö")
|
||||||
|
str = string.gsub(str, "Ö", "Ö")
|
||||||
|
str = string.gsub(str, "ö", "ö")
|
||||||
|
str = string.gsub(str, "Ö", "Ö")
|
||||||
|
str = string.gsub(str, "ü", "ü")
|
||||||
|
str = string.gsub(str, "Ü", "Ü")
|
||||||
|
str = string.gsub(str, "ü", "ü")
|
||||||
|
str = string.gsub(str, "Ü", "Ü")
|
||||||
|
-- str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end ) <- There is a bug, but I don't know!?
|
||||||
|
str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
|
||||||
|
str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
local function get_base_redis(id, option, extra)
|
local function get_base_redis(id, option, extra)
|
||||||
local ex = ''
|
local ex = ''
|
||||||
if option ~= nil then
|
if option ~= nil then
|
||||||
@ -123,6 +161,7 @@ local function cron()
|
|||||||
local keys = redis:keys(get_base_redis("*", "subs"))
|
local keys = redis:keys(get_base_redis("*", "subs"))
|
||||||
for k,v in pairs(keys) do
|
for k,v in pairs(keys) do
|
||||||
local base = string.match(v, "rss:(.+):subs") -- Get the URL base
|
local base = string.match(v, "rss:(.+):subs") -- Get the URL base
|
||||||
|
--print('Checke RSS: '..base)
|
||||||
local prot = redis:get(get_base_redis(base, "protocol"))
|
local prot = redis:get(get_base_redis(base, "protocol"))
|
||||||
local last = redis:get(get_base_redis(base, "last_entry"))
|
local last = redis:get(get_base_redis(base, "last_entry"))
|
||||||
local url = prot .. "://" .. base
|
local url = prot .. "://" .. base
|
||||||
@ -132,12 +171,16 @@ local function cron()
|
|||||||
end
|
end
|
||||||
local newentr = get_new_entries(last, parsed.entries)
|
local newentr = get_new_entries(last, parsed.entries)
|
||||||
local subscribers = {}
|
local subscribers = {}
|
||||||
local text = '' -- Send only one message with all updates
|
local text = '' -- Send one message per feed with the latest entries
|
||||||
for k2, v2 in pairs(newentr) do
|
for k2, v2 in pairs(newentr) do
|
||||||
local title = v2.title or 'No title'
|
local title = v2.title or 'Kein Titel'
|
||||||
local link = v2.link or v2.id or 'No Link'
|
local link = v2.link or v2.id or 'Kein Link'
|
||||||
--text = string.gsub(text, "\n", "")
|
if v2.content then
|
||||||
text = text .. '[RSS] '.. title .. '\n(' .. link .. ')\n\n'
|
content = string.sub(unescape_for_rss(v2.content:gsub("%b<>", "")), 1, 250) .. '...'
|
||||||
|
else
|
||||||
|
content = string.sub(unescape_for_rss(v2.summary:gsub("%b<>", "")), 1, 250) .. '...'
|
||||||
|
end
|
||||||
|
text = text .. '[RSS] '.. title .. '\n'..content..'\n\n(' .. link .. ')\n\n'
|
||||||
end
|
end
|
||||||
if text ~= '' then
|
if text ~= '' then
|
||||||
local newlast = newentr[1].id
|
local newlast = newentr[1].id
|
||||||
|
Reference in New Issue
Block a user