rsslair/scripts/godot.lua

38 lines
1.3 KiB
Lua

add_route('godot', '/godot')
-- Live Website
-- THIS WORKS!!!
function godot.route(args)
-- Get the RSS Feed
local rssFeed = rss:get("https://godotengine.org/rss.xml")
local entries = parse_xml_feed(rssFeed)
local newEntries = {}
local scraped, to_scrape = db:check(entries)
-- Accuumulate the entries
for _, entry in ipairs(to_scrape) do
log.debug("Scraping: " .. entry:link())
-- Get the article
local article = get(entry:link())
local article_html = html.new(article)
-- Get the article body
local content = article_html:select("div.article-body")
-- Update the entry
entry:description(content)
-- Add the entry to the list
db:insert(entry)
table.insert(newEntries, entry)
os.execute("sleep 0.25")
end
-- Get the already scraped entries from the database
local localEntries = db:getRss(scraped)
-- TODO: Handle case where there are no local entries
local newFeed = rss.merge(localEntries, newEntries)
-- Create a new rss feed
local image = RssImage.new("Godot Engine Official", "https://godotengine.org/favicon.ico", "https://godotengine.org")
local feed = create_rss_feed("Godot Engine Official", "https://godotengine.org", image, newFeed)
return feed
end