Make title on comment optional.
This commit is contained in:
25
src/probe.rs
25
src/probe.rs
@@ -50,7 +50,7 @@ impl fmt::Display for Entry {
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Comment {
|
pub struct Comment {
|
||||||
pub datetime: DateTime<Utc>,
|
pub datetime: DateTime<Utc>,
|
||||||
pub title: String,
|
pub title: Option<String>,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,13 +58,22 @@ impl fmt::Display for Comment {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let datetime = self.datetime.with_timezone(&Local);
|
let datetime = self.datetime.with_timezone(&Local);
|
||||||
|
|
||||||
write!(
|
if let Some(ref title) = self.title {
|
||||||
f,
|
write!(
|
||||||
"{}: {} - {}",
|
f,
|
||||||
datetime.format("%Y-%m-%d %H:%M:%S"),
|
"{}: {} - {}",
|
||||||
self.title,
|
datetime.format("%Y-%m-%d %H:%M:%S"),
|
||||||
self.message
|
title,
|
||||||
)
|
self.message
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}: {}",
|
||||||
|
datetime.format("%Y-%m-%d %H:%M:%S"),
|
||||||
|
self.message
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ fn from_html(document: &str) -> Result<Entry, ()> {
|
|||||||
(comment.timestamp / 1000) as i64,
|
(comment.timestamp / 1000) as i64,
|
||||||
(comment.timestamp % 1000) as u32,
|
(comment.timestamp % 1000) as u32,
|
||||||
),
|
),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: comment.comment,
|
message: comment.comment,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -142,147 +142,147 @@ mod tests {
|
|||||||
comments: vec![
|
comments: vec![
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2019-01-17T17:29:22Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2019-01-17T17:29:22Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Varmsälj från Folksam".to_string(),
|
message: "Varmsälj från Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-12-14T13:45:28Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-12-14T13:45:28Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam".to_string(),
|
message: "Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-11-28T07:30:18Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-11-28T07:30:18Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Höglandschskt".to_string(),
|
message: "Höglandschskt".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-11-20T19:18:09Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-11-20T19:18:09Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Försäljare ".to_string(),
|
message: "Försäljare ".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-11-19T17:38:34Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-11-19T17:38:34Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "mögg från Folksam".to_string(),
|
message: "mögg från Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-11-12T16:00:41Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-11-12T16:00:41Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam försäkringsförsäljare".to_string(),
|
message: "Folksam försäkringsförsäljare".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-10-25T10:28:36Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-10-25T10:28:36Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "folksam".to_string(),
|
message: "folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-10-10T07:30:40Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-10-10T07:30:40Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Telefonförsäljare".to_string(),
|
message: "Telefonförsäljare".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-10-04T10:04:55Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-10-04T10:04:55Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam säljare".to_string(),
|
message: "Folksam säljare".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-10-03T13:55:19Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-10-03T13:55:19Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Sa inget.".to_string(),
|
message: "Sa inget.".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-24T16:56:46Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-24T16:56:46Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam".to_string(),
|
message: "Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-24T09:42:43Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-24T09:42:43Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Achmati azmut från folksam".to_string(),
|
message: "Achmati azmut från folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-21T18:29:29Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-21T18:29:29Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam".to_string(),
|
message: "Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-16T18:56:56Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-16T18:56:56Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Säljare från Folksam.".to_string(),
|
message: "Säljare från Folksam.".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-16T14:48:59Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-16T14:48:59Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam ".to_string(),
|
message: "Folksam ".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-09T16:30:28Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-09T16:30:28Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam".to_string(),
|
message: "Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-02T16:29:32Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-02T16:29:32Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam ".to_string(),
|
message: "Folksam ".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-08-02T15:33:38Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-08-02T15:33:38Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam ".to_string(),
|
message: "Folksam ".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-07-25T08:28:27Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-07-25T08:28:27Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Säljare Folksam".to_string(),
|
message: "Säljare Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-07-17T21:20:51Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-07-17T21:20:51Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Inga Hansson ".to_string(),
|
message: "Inga Hansson ".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-07-16T18:11:46Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-07-16T18:11:46Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam".to_string(),
|
message: "Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-07-06T15:45:46Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-07-06T15:45:46Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam ".to_string(),
|
message: "Folksam ".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-07-05T17:24:07Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-07-05T17:24:07Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "folksam".to_string(),
|
message: "folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-07-05T11:15:02Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-07-05T11:15:02Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Vesran".to_string(),
|
message: "Vesran".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-07-04T13:30:49Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-07-04T13:30:49Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam".to_string(),
|
message: "Folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-06-29T10:52:51Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-06-29T10:52:51Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "folksam".to_string(),
|
message: "folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-06-28T13:33:01Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-06-28T13:33:01Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Säljare folksam".to_string(),
|
message: "Säljare folksam".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-06-28T07:42:42Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-06-28T07:42:42Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Folksam försäkringar".to_string(),
|
message: "Folksam försäkringar".to_string(),
|
||||||
},
|
},
|
||||||
probe::Comment {
|
probe::Comment {
|
||||||
datetime: "2018-06-26T12:59:33Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-06-26T12:59:33Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Säljare Folksam".to_string(),
|
message: "Säljare Folksam".to_string(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ fn from_html(document: &str) -> Result<Entry, ()> {
|
|||||||
|
|
||||||
comments.push(Comment {
|
comments.push(Comment {
|
||||||
datetime: stockholm_to_utc(&datetime, "%Y-%m-%d %H:%M:%S").unwrap(),
|
datetime: stockholm_to_utc(&datetime, "%Y-%m-%d %H:%M:%S").unwrap(),
|
||||||
title,
|
title: if title.is_empty() { None } else { Some(title) },
|
||||||
message,
|
message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -132,32 +132,32 @@ mod tests {
|
|||||||
comments: vec![
|
comments: vec![
|
||||||
Comment {
|
Comment {
|
||||||
datetime: "2018-05-09T12:31:39Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-05-09T12:31:39Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "Folksam".to_string(),
|
title: Some("Folksam".to_string()),
|
||||||
message: "Svara inte på okända nummer. Blockerat!".to_string(),
|
message: "Svara inte på okända nummer. Blockerat!".to_string(),
|
||||||
},
|
},
|
||||||
Comment {
|
Comment {
|
||||||
datetime: "2017-12-05T16:33:10Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2017-12-05T16:33:10Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "Folksam".to_string(),
|
title: Some("Folksam".to_string()),
|
||||||
message: "Svarade aldrig men när jag ringde upp var det Folksam".to_string(),
|
message: "Svarade aldrig men när jag ringde upp var det Folksam".to_string(),
|
||||||
},
|
},
|
||||||
Comment {
|
Comment {
|
||||||
datetime: "2017-11-28T10:30:10Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2017-11-28T10:30:10Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "".to_string(),
|
title: None,
|
||||||
message: "Ringde och la på".to_string(),
|
message: "Ringde och la på".to_string(),
|
||||||
},
|
},
|
||||||
Comment {
|
Comment {
|
||||||
datetime: "2017-11-20T14:53:16Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2017-11-20T14:53:16Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "Folksam".to_string(),
|
title: Some("Folksam".to_string()),
|
||||||
message: "färsäljare".to_string(),
|
message: "färsäljare".to_string(),
|
||||||
},
|
},
|
||||||
Comment {
|
Comment {
|
||||||
datetime: "2017-11-16T12:38:07Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2017-11-16T12:38:07Z".parse::<DateTime<Utc>>().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(),
|
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 {
|
Comment {
|
||||||
datetime: "2017-10-25T05:59:26Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2017-10-25T05:59:26Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "Folksam".to_string(),
|
title: Some("Folksam".to_string()),
|
||||||
message: "Försäljare".to_string(),
|
message: "Försäljare".to_string(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -189,7 +189,7 @@ mod tests {
|
|||||||
comments: vec![
|
comments: vec![
|
||||||
Comment {
|
Comment {
|
||||||
datetime: "2019-01-18T13:30:55Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2019-01-18T13:30:55Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "Alnö Design & Produktion AB".to_string(),
|
title: Some("Alnö Design & Produktion AB".to_string()),
|
||||||
message: "Renhållning, service, kemprodukter".to_string(),
|
message: "Renhållning, service, kemprodukter".to_string(),
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -208,7 +208,7 @@ mod tests {
|
|||||||
comments: vec![
|
comments: vec![
|
||||||
Comment {
|
Comment {
|
||||||
datetime: "2018-10-31T17:48:27Z".parse::<DateTime<Utc>>().unwrap(),
|
datetime: "2018-10-31T17:48:27Z".parse::<DateTime<Utc>>().unwrap(),
|
||||||
title: "Tele2".to_string(),
|
title: Some("Tele2".to_string()),
|
||||||
message: "Bättre priser som inte finns online".to_string(),
|
message: "Bättre priser som inte finns online".to_string(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user