Document techcrunch lua script

This commit is contained in:
Christopher Williams 2024-09-22 12:42:41 -04:00
parent c8686df817
commit f22c2e443c
2 changed files with 19 additions and 19 deletions

View File

@ -1,26 +1,26 @@
local WEBSITE_NAME = "9to5mac"
local WEBSITE_HOME = "https://9to5mac.com"
local WEBSITE_NAME = "TechCrunch"
local WEBSITE_HOME = "https://techcrunch.com"
add_route("techCrunch", "/TechCrunch")
techCrunch = {}
function techCrunch.route(args)
local xml = get("http://localhost:8081/feed.xml")
local rss_parser = Feed()
local feed = rss_parser:new(xml)
local xml = get("http://localhost:8081/feed.xml") -- Get an xml RSS feed
local rss_parser = Feed() -- Create a new instance of the Feed object
local feed = rss_parser:new(xml) -- Parse the xml into a feed object
local articles = feed.channel.articles
local article = articles[1]
print('Article Title: ' .. article.title)
print('Article Link: ' .. article.link)
local articles = feed.channel.articles -- Get all of the article objects
local article = articles[1] -- Get the first article object
log:info("Title: " .. article.title)
log:info("Description: " .. article.description)
local article_content = get(article.link)
local html_parser = HtmlParser()
html_parser:parse(article_content)
local article_content = get(article.link) -- Get the entire article content
local html_parser = HtmlParser() -- Create a new instance of the html parser
html_parser:parse(article_content) -- Parse the article into an html tree
local elements = html_parser:select_element('.wp-block-post-content')
print('Selected Elements')
local element = elements[1]
article.description = element
local elements = html_parser:select_element('.wp-block-post-content') -- Select the element with the class 'wp-block-post-content'
local element = elements[1] -- String of the html from the element selected
article.description = element -- Replace the description with the entire article
return feed:render()
end

View File

@ -1,4 +1,4 @@
use log::debug;
use log::{debug, error};
use mlua::{UserData, UserDataMethods};
use scraper::{Html, Selector};
@ -29,11 +29,11 @@ impl HtmlParser {
match selector {
Ok(selector) => {
let elements: Vec<_> = self.doc.select(&selector).collect();
println!("Found {} elements", elements.len());
debug!("Found {} elements", elements.len());
elements.iter().map(|x| x.html()).collect()
}
Err(e) => {
println!("Error: {}", e);
error!("{}", e);
vec![]
}
}