Add matched expression to notification (#4)

This commit is contained in:
Dave Gallant
2020-06-21 15:25:03 -04:00
committed by GitHub
parent 9ef16bc75f
commit b9bec9479c
2 changed files with 17 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ use sendgrid::{Destination, Mail};
const RFD_FORUMS_BASE_URL: &str = "https://forums.redflagdeals.com"; const RFD_FORUMS_BASE_URL: &str = "https://forums.redflagdeals.com";
pub fn send(topic: &Topic, posts: &Posts, config: &Config) { pub fn send(topic: &Topic, posts: &Posts, expression: &str, config: &Config) {
let api_key = &config.sendgrid.api_key; let api_key = &config.sendgrid.api_key;
let sg = SGClient::new(api_key.to_string()); let sg = SGClient::new(api_key.to_string());
@@ -14,22 +14,28 @@ pub fn send(topic: &Topic, posts: &Posts, config: &Config) {
"\ "\
<b>First Posted:</b> {} <b>First Posted:</b> {}
<br> <br>
<b>DEALER:</b> {:?} <b>DEALER:</b> {}
<br> <br>
<b>DEAL:</b> {:?} <b>DEAL:</b> {}
<br> <br>
<b>POST:</b> {}\ <b>POST:</b> {}\
<br> <br>
<br> <br>
<b>Body:</b> {} <b>Body:</b> {}
<br>
<br>
<b>Matched by expression:</b> {}
", ",
topic.post_time, topic.post_time,
topic.offer.dealer_name, topic.offer.dealer_name.as_ref().unwrap_or(&"".to_string()),
topic.offer.url, topic.offer.url.as_ref().unwrap_or(&"".to_string()),
format!("{}/{}", RFD_FORUMS_BASE_URL, topic.web_path), format!("{}/{}", RFD_FORUMS_BASE_URL, topic.web_path),
posts.posts[0].body, posts.posts[0].body,
expression,
); );
debug!("{}", html_message);
let mail_info = Mail::new() let mail_info = Mail::new()
.add_to(Destination { .add_to(Destination {
address: &config.sendgrid.mail_to, address: &config.sendgrid.mail_to,

View File

@@ -6,22 +6,22 @@ use crypto::sha2::Sha256;
use regex::RegexBuilder; use regex::RegexBuilder;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize)]
pub struct Deals { pub struct Deals {
topics: Vec<Topic>, topics: Vec<Topic>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize)]
pub struct Posts { pub struct Posts {
pub posts: Vec<Post>, pub posts: Vec<Post>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize)]
pub struct Post { pub struct Post {
pub body: String, pub body: String,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize)]
pub struct Topic { pub struct Topic {
#[serde(rename = "topic_id")] #[serde(rename = "topic_id")]
pub id: u32, pub id: u32,
@@ -31,7 +31,7 @@ pub struct Topic {
pub offer: Offer, pub offer: Offer,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize)]
pub struct Offer { pub struct Offer {
pub dealer_name: Option<String>, pub dealer_name: Option<String>,
pub url: Option<String>, pub url: Option<String>,
@@ -111,7 +111,7 @@ pub fn match_deals(deals: Deals, config: Config) {
.unwrap(), .unwrap(),
); );
db::insert(&deal_hash); db::insert(&deal_hash);
mail::send(topic, &posts, &config); mail::send(topic, &posts, expression, &config);
} }
} }
} }