limpiar código

This commit is contained in:
Cat /dev/Nulo 2024-01-12 10:52:13 -03:00
parent c1111b112e
commit d233dbd259
3 changed files with 6 additions and 11 deletions

View file

@ -208,8 +208,7 @@ async fn parse_file_cli(file_path: String) -> anyhow::Result<()> {
dom.query_selector("link[rel=\"canonical\"]") dom.query_selector("link[rel=\"canonical\"]")
.unwrap() .unwrap()
.filter_map(|h| h.get(dom.parser())) .filter_map(|h| h.get(dom.parser()))
.filter_map(|n| n.as_tag()) .find_map(|n| n.as_tag())
.next()
.and_then(|t| t.attributes().get("href").flatten()) .and_then(|t| t.attributes().get("href").flatten())
.expect("No meta canonical") .expect("No meta canonical")
.as_utf8_str() .as_utf8_str()

View file

@ -24,8 +24,7 @@ pub fn parse(url: String, dom: &tl::VDom) -> Result<PrecioPoint, anyhow::Error>
.query_selector(".atg_store_newPrice") .query_selector(".atg_store_newPrice")
.unwrap() .unwrap()
.filter_map(|h| h.get(dom.parser())) .filter_map(|h| h.get(dom.parser()))
.filter_map(|n| n.as_tag()) .find_map(|n| n.as_tag())
.next()
.map(|t| t.inner_text(dom.parser())) .map(|t| t.inner_text(dom.parser()))
.filter(|s| !s.is_empty()) .filter(|s| !s.is_empty())
.map(|s| { .map(|s| {
@ -41,8 +40,7 @@ pub fn parse(url: String, dom: &tl::VDom) -> Result<PrecioPoint, anyhow::Error>
dom.query_selector(".product_not_available") dom.query_selector(".product_not_available")
.unwrap() .unwrap()
.filter_map(|h| h.get(dom.parser())) .filter_map(|h| h.get(dom.parser()))
.filter_map(|n| n.as_tag()) .find_map(|n| n.as_tag())
.next()
.is_some(), .is_some(),
); );
@ -50,8 +48,7 @@ pub fn parse(url: String, dom: &tl::VDom) -> Result<PrecioPoint, anyhow::Error>
.query_selector("h1.product_page") .query_selector("h1.product_page")
.unwrap() .unwrap()
.filter_map(|h| h.get(dom.parser())) .filter_map(|h| h.get(dom.parser()))
.filter_map(|n| n.as_tag()) .find_map(|n| n.as_tag())
.next()
.map(|t| t.inner_text(dom.parser())) .map(|t| t.inner_text(dom.parser()))
.map(|s| s.trim().to_string()); .map(|s| s.trim().to_string());
@ -59,8 +56,7 @@ pub fn parse(url: String, dom: &tl::VDom) -> Result<PrecioPoint, anyhow::Error>
.query_selector(".zoomImage1") .query_selector(".zoomImage1")
.unwrap() .unwrap()
.filter_map(|h| h.get(dom.parser())) .filter_map(|h| h.get(dom.parser()))
.filter_map(|n| n.as_tag()) .find_map(|n| n.as_tag())
.next()
.and_then(|t| t.attributes().get("src").flatten()) .and_then(|t| t.attributes().get("src").flatten())
.map(|s| s.as_utf8_str().to_string()); .map(|s| s.as_utf8_str().to_string());

View file

@ -125,7 +125,7 @@ pub async fn get_urls_from_sitemap<'a>(sitemaps: &[&str]) -> anyhow::Result<Vec<
let client = &client; let client = &client;
async move { async move {
let text = get_retry_policy() let text = get_retry_policy()
.retry(|| do_request(client, &url)) .retry(|| do_request(client, url))
.await? .await?
.text() .text()
.await?; .await?;