From a1d11c976d385f116784e46c38aa059c716a2a69 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Tue, 22 Jan 2019 11:36:31 +0100 Subject: [PATCH] Make title on comment optional. --- src/probe.rs | 25 +++++++++----- src/probe/hitta.rs | 60 +++++++++++++++++----------------- src/probe/telefonforsaljare.rs | 18 +++++----- 3 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/probe.rs b/src/probe.rs index da2c7db..a70e34c 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -50,7 +50,7 @@ impl fmt::Display for Entry { #[derive(Debug, PartialEq)] pub struct Comment { pub datetime: DateTime, - pub title: String, + pub title: Option, pub message: String, } @@ -58,13 +58,22 @@ impl fmt::Display for Comment { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let datetime = self.datetime.with_timezone(&Local); - write!( - f, - "{}: {} - {}", - datetime.format("%Y-%m-%d %H:%M:%S"), - self.title, - self.message - ) + if let Some(ref title) = self.title { + write!( + f, + "{}: {} - {}", + datetime.format("%Y-%m-%d %H:%M:%S"), + title, + self.message + ) + } else { + write!( + f, + "{}: {}", + datetime.format("%Y-%m-%d %H:%M:%S"), + self.message + ) + } } } diff --git a/src/probe/hitta.rs b/src/probe/hitta.rs index 6f2ccff..dadc0b6 100644 --- a/src/probe/hitta.rs +++ b/src/probe/hitta.rs @@ -72,7 +72,7 @@ fn from_html(document: &str) -> Result { (comment.timestamp / 1000) as i64, (comment.timestamp % 1000) as u32, ), - title: "".to_string(), + title: None, message: comment.comment, }); } @@ -142,147 +142,147 @@ mod tests { comments: vec![ probe::Comment { datetime: "2019-01-17T17:29:22Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Varmsälj från Folksam".to_string(), }, probe::Comment { datetime: "2018-12-14T13:45:28Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam".to_string(), }, probe::Comment { datetime: "2018-11-28T07:30:18Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Höglandschskt".to_string(), }, probe::Comment { datetime: "2018-11-20T19:18:09Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Försäljare ".to_string(), }, probe::Comment { datetime: "2018-11-19T17:38:34Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "mögg från Folksam".to_string(), }, probe::Comment { datetime: "2018-11-12T16:00:41Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam försäkringsförsäljare".to_string(), }, probe::Comment { datetime: "2018-10-25T10:28:36Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "folksam".to_string(), }, probe::Comment { datetime: "2018-10-10T07:30:40Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Telefonförsäljare".to_string(), }, probe::Comment { datetime: "2018-10-04T10:04:55Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam säljare".to_string(), }, probe::Comment { datetime: "2018-10-03T13:55:19Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Sa inget.".to_string(), }, probe::Comment { datetime: "2018-08-24T16:56:46Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam".to_string(), }, probe::Comment { datetime: "2018-08-24T09:42:43Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Achmati azmut från folksam".to_string(), }, probe::Comment { datetime: "2018-08-21T18:29:29Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam".to_string(), }, probe::Comment { datetime: "2018-08-16T18:56:56Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Säljare från Folksam.".to_string(), }, probe::Comment { datetime: "2018-08-16T14:48:59Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam ".to_string(), }, probe::Comment { datetime: "2018-08-09T16:30:28Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam".to_string(), }, probe::Comment { datetime: "2018-08-02T16:29:32Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam ".to_string(), }, probe::Comment { datetime: "2018-08-02T15:33:38Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam ".to_string(), }, probe::Comment { datetime: "2018-07-25T08:28:27Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Säljare Folksam".to_string(), }, probe::Comment { datetime: "2018-07-17T21:20:51Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Inga Hansson ".to_string(), }, probe::Comment { datetime: "2018-07-16T18:11:46Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam".to_string(), }, probe::Comment { datetime: "2018-07-06T15:45:46Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam ".to_string(), }, probe::Comment { datetime: "2018-07-05T17:24:07Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "folksam".to_string(), }, probe::Comment { datetime: "2018-07-05T11:15:02Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Vesran".to_string(), }, probe::Comment { datetime: "2018-07-04T13:30:49Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam".to_string(), }, probe::Comment { datetime: "2018-06-29T10:52:51Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "folksam".to_string(), }, probe::Comment { datetime: "2018-06-28T13:33:01Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Säljare folksam".to_string(), }, probe::Comment { datetime: "2018-06-28T07:42:42Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Folksam försäkringar".to_string(), }, probe::Comment { datetime: "2018-06-26T12:59:33Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Säljare Folksam".to_string(), }, ], diff --git a/src/probe/telefonforsaljare.rs b/src/probe/telefonforsaljare.rs index a71d9eb..1771dad 100644 --- a/src/probe/telefonforsaljare.rs +++ b/src/probe/telefonforsaljare.rs @@ -68,7 +68,7 @@ fn from_html(document: &str) -> Result { comments.push(Comment { datetime: stockholm_to_utc(&datetime, "%Y-%m-%d %H:%M:%S").unwrap(), - title, + title: if title.is_empty() { None } else { Some(title) }, message, }); } @@ -132,32 +132,32 @@ mod tests { comments: vec![ Comment { datetime: "2018-05-09T12:31:39Z".parse::>().unwrap(), - title: "Folksam".to_string(), + title: Some("Folksam".to_string()), message: "Svara inte på okända nummer. Blockerat!".to_string(), }, Comment { datetime: "2017-12-05T16:33:10Z".parse::>().unwrap(), - title: "Folksam".to_string(), + title: Some("Folksam".to_string()), message: "Svarade aldrig men när jag ringde upp var det Folksam".to_string(), }, Comment { datetime: "2017-11-28T10:30:10Z".parse::>().unwrap(), - title: "".to_string(), + title: None, message: "Ringde och la på".to_string(), }, Comment { datetime: "2017-11-20T14:53:16Z".parse::>().unwrap(), - title: "Folksam".to_string(), + title: Some("Folksam".to_string()), message: "färsäljare".to_string(), }, Comment { datetime: "2017-11-16T12:38:07Z".parse::>().unwrap(), - title: "Folksam".to_string(), + title: Some("Folksam".to_string()), message: "missat samtal, ringde tillbaka och automatsvar sa att det var folksam som sökt mig för att presentera ett erbjudande.".to_string(), }, Comment { datetime: "2017-10-25T05:59:26Z".parse::>().unwrap(), - title: "Folksam".to_string(), + title: Some("Folksam".to_string()), message: "Försäljare".to_string(), }, ], @@ -189,7 +189,7 @@ mod tests { comments: vec![ Comment { datetime: "2019-01-18T13:30:55Z".parse::>().unwrap(), - title: "Alnö Design & Produktion AB".to_string(), + title: Some("Alnö Design & Produktion AB".to_string()), message: "Renhållning, service, kemprodukter".to_string(), } ], @@ -208,7 +208,7 @@ mod tests { comments: vec![ Comment { datetime: "2018-10-31T17:48:27Z".parse::>().unwrap(), - title: "Tele2".to_string(), + title: Some("Tele2".to_string()), message: "Bättre priser som inte finns online".to_string(), }, ],