rsslair/scripts/9to5mac.lua

47 lines
1.5 KiB
Lua

local WEBSITE_NAME = "9to5mac"
local WEBSITE_HOME = "https://9to5mac.com"
add_route("Nineto5mac", "/9to5mac")
Nineto5mac = {}
function Nineto5mac.route(args)
local xml = get("https://9to5mac.com/feed/")
local rss_parser = Feed()
local feed = rss_parser:new(xml)
local articles = feed.channel.articles
local existing_articles = db:check_if_articles_in_feed_exist(feed)
log:debug("Fetching missing articles from the database")
for _, article in ipairs(articles) do
if existing_articles[article.guid.value] then
log:debug("Article already exists in the database: " .. article.title)
article.description = existing_articles[article.guid.value]
goto continue
end
log:debug("Getting article: " .. article.title .. " from " .. article.link)
local article_content = get(article.link)
local html_parser = HtmlParser()
html_parser:parse(article_content)
-- Remove sections
html_parser:delete_element("header")
html_parser:delete_element("script")
html_parser:delete_element(".ad-disclaimer-container")
html_parser:delete_element("#after_disclaimer_placement")
html_parser:delete_element(".adsbygoogle")
html_parser:delete_element(".google-news-link")
local elements = html_parser:select_element('.post-content')
local element = elements
[1]
article.description =
element
sleep(500)
::continue::
end
return feed:render(), feed
end