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 (<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)))
+
+ 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.