rss.lua: dreckiger Weg um site_title zu bekommen

Änder ich später, wenn ich weiß wie ._.
This commit is contained in:
Akamaru 2016-10-19 21:57:38 +02:00
parent 95f00e5870
commit 4f6abf917e

View File

@ -305,6 +305,15 @@ function rss:action(msg, config, matches)
return return
end end
function get_site_name(feed_link) --i know there's a better way to get this. But atm idc ¯\_(ツ)_/¯
local iframely_api_key = cred_data.iframely_api_key
local res, code = https.request('https://iframe.ly/api/oembed?url='..feed_link..'&api_key='..iframely_api_key)
if code ~= 200 then return end
local data = json.decode(res)
local feed_name = data.provider_name
return feed_name
end
function rss:cron() function rss: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
@ -317,11 +326,6 @@ function rss:cron()
if err ~= nil then if err ~= nil then
return return
end end
if not parsed.feed.title then
feed_title = parsed.feed.link
else
feed_title = parsed.feed.title
end
local newentr = get_new_entries(last, parsed.entries) local newentr = get_new_entries(last, parsed.entries)
local subscribers = {} local subscribers = {}
local text = '' -- Send one message per feed with the latest entries local text = '' -- Send one message per feed with the latest entries
@ -339,6 +343,10 @@ function rss:cron()
end end
local link_name = link_name:gsub('^www%.', '') local link_name = link_name:gsub('^www%.', '')
local link_name = link_name:gsub('^www1%.', '') local link_name = link_name:gsub('^www1%.', '')
local site_title = get_site_name(link)
if not site_title then
site_title = link_name
end
if v2.content then if v2.content then
content = v2.content:gsub("%b<>", "") content = v2.content:gsub("%b<>", "")
@ -363,7 +371,7 @@ function rss:cron()
else else
content = '' content = ''
end end
text = text..'\n<b>[</b>#RSS<b>] '..title..'</b>\n<i>'..feed_title..'</i>\n'..utilities.trim(content)..'\n<a href="'..link..'">Auf '..link_name..' ansehen.</a>\n' text = text..'\n<b>[</b>#RSS<b>] '..title..'</b>\n<i>~ '..site_title..' ~</i>\n'..utilities.trim(content)..'\n<a href="'..link..'">Auf '..link_name..' ansehen.</a>\n'
end end
if text ~= '' then if text ~= '' then
local newlast = newentr[1].id local newlast = newentr[1].id