X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=src%2Fmain.rs;fp=src%2Fmain.rs;h=aeafb571d572e78a17c82dca940eba7f8553a2db;hb=c007616f22e09b3076dd566cdd0cf3acca5bd100;hp=9eca6497dd10185456b238a3e1028491d65c8b6c;hpb=1bfe2373f1fbb8f58cbaa025706acedc4e2919a7;p=rtx3080.git diff --git a/src/main.rs b/src/main.rs index 9eca649..aeafb57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,35 +51,39 @@ fn main() -> Result<(), Box> { loop { println!("Request: {}", url); - let resp = client.get(&url).send()?; - - if resp.status().is_success() { - let html = resp.text()?; - let document = Html::parse_document(&html); - - // A vector of (, <url>), empty if nothing matches. - let match_items: Vec<(String, String)> = - document.select(&selector).filter_map( - |element| { - if let (Some(title), Some(url_to_item)) = (element.value().attr("title"), element.value().attr("href")) { - if title.find(to_match).is_some() { - return Some((String::from(title), String::from(url_to_item))) + + match client.get(&url).send() { + Ok(resp) => + if resp.status().is_success() { + let html = resp.text()?; + let document = Html::parse_document(&html); + + // A vector of (<title>, <url>), empty if nothing matches. + let match_items: Vec<(String, String)> = + document.select(&selector).filter_map( + |element| { + if let (Some(title), Some(url_to_item)) = (element.value().attr("title"), element.value().attr("href")) { + if title.find(to_match).is_some() { + return Some((String::from(title), String::from(url_to_item))) + } + } + None } - } - None + ).collect(); + + if match_items.is_empty() { + println!("No matches..."); + } else if send_email(&match_items[..], &config.smtp_login, &config.smtp_password) { + println!("Some matches has been found! An e-mail has been sent!"); + return Ok(()) + } else { + println!("Unable to send e-mail"); } - ).collect(); - - if match_items.is_empty() { - println!("No matches..."); - } else if send_email(&match_items[..], &config.smtp_login, &config.smtp_password) { - println!("Some matches has been found! An e-mail has been sent!"); - return Ok(()) - } else { - println!("Unable to send e-mail"); - } - } else { - println!("Request unsuccessful:\n{:#?}", resp); + } else { + println!("Request unsuccessful:\n{:#?}", resp); + }, + Err(error) => + println!("Error during request: {:?}", error) } thread::sleep(time::Duration::from_secs(60)); // 1 min.