renamed time_tracker to chrono_track
This commit is contained in:
parent
02b7127d30
commit
c728c44521
3 changed files with 62 additions and 26 deletions
|
@ -1,5 +1,5 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"status_cloud",
|
"status_cloud",
|
||||||
"time_tracker"
|
"chrono_track"
|
||||||
]
|
]
|
||||||
|
|
|
@ -2,7 +2,7 @@ use chrono::{DateTime, Datelike, Utc};
|
||||||
use chrono_tz::US::Central;
|
use chrono_tz::US::Central;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use lettre::{
|
use lettre::{
|
||||||
message::{Message, header::ContentType, Attachment, MultiPart, SinglePart},
|
message::{header::ContentType, Attachment, Message, MultiPart, SinglePart},
|
||||||
SendmailTransport, Transport,
|
SendmailTransport, Transport,
|
||||||
};
|
};
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
|
@ -196,7 +196,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if do_email_summary {
|
if do_email_summary {
|
||||||
debug!("Send email selected");
|
debug!("Send email selected");
|
||||||
reset_email_checkbox(&cfg);
|
reset_email_checkbox(&cfg);
|
||||||
send_email_summary(&cfg, body_content);
|
send_email_summary(&cfg, body_content, &args);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -236,6 +236,9 @@ struct CliArgs {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
config_file: PathBuf,
|
config_file: PathBuf,
|
||||||
|
|
||||||
|
#[arg(short, long)]
|
||||||
|
from_addr: String,
|
||||||
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
debug: bool,
|
debug: bool,
|
||||||
}
|
}
|
||||||
|
@ -299,14 +302,14 @@ struct SummaryRow {
|
||||||
// All calls after depend on the success of the one before, and cannot run
|
// All calls after depend on the success of the one before, and cannot run
|
||||||
// without. So it would be too much work to make an error type to handle an error
|
// without. So it would be too much work to make an error type to handle an error
|
||||||
// that would cause a crash anyways
|
// that would cause a crash anyways
|
||||||
fn send_email_summary(config: &Config, body_content: Vec<String>) {
|
fn send_email_summary(config: &Config, body_content: Vec<String>, cliargs: &CliArgs) {
|
||||||
let mut wtr = csv::Writer::from_writer(vec![]);
|
let mut wtr = csv::Writer::from_writer(vec![]);
|
||||||
|
|
||||||
for line in body_content {
|
for line in body_content {
|
||||||
if line.starts_with("### ") {
|
if line.starts_with("### ") {
|
||||||
let mut split: Vec<&str> = line.split('|').collect();
|
let mut split: Vec<&str> = line.split('|').collect();
|
||||||
if split.len() != 3 {
|
if split.len() != 3 {
|
||||||
error!("There was an issue with this line: {line}");
|
error!("There was an issue with this line. 3 splits not found: {line}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let date: String = match split.pop() {
|
let date: String = match split.pop() {
|
||||||
|
@ -355,36 +358,70 @@ fn send_email_summary(config: &Config, body_content: Vec<String>) {
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace("### ", "");
|
.replace("### ", "");
|
||||||
|
|
||||||
wtr.serialize(SummaryRow { date: date.trim().to_string(), total_time: time, task_name }).unwrap();
|
match wtr.serialize(SummaryRow {
|
||||||
|
date: date.trim().to_string(),
|
||||||
|
total_time: time,
|
||||||
|
task_name,
|
||||||
|
}) {
|
||||||
|
Ok(_) => continue,
|
||||||
|
Err(e) => {
|
||||||
|
error!("There was an error serializing the csv, aborting: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = String::from_utf8(wtr.into_inner().unwrap()).unwrap();
|
let data = match String::from_utf8(wtr.into_inner().unwrap()) {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(e) => {
|
||||||
|
error!("There was an error converting the csv writer to a string, aborting: {e}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
debug!("{:#?}", data);
|
debug!("{:#?}", data);
|
||||||
|
|
||||||
let attachment = Attachment::new("TimeSummary.csv".to_string()).body(data, ContentType::parse("text/csv").unwrap());
|
let attachment = Attachment::new("TimeSummary.csv".to_string())
|
||||||
|
// The unwrap is on a constant value
|
||||||
|
.body(data, ContentType::parse("text/csv").unwrap());
|
||||||
|
|
||||||
const HTML: &str = r#"
|
const HTML: &str = r#"
|
||||||
!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Hello from Lettre!</title>
|
<title>ChronoTrack Export</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div style="background-color: #33ccff; border-radius: 40px; height: 100px"></div>
|
||||||
<div style="display: flex; flex-direction: column; align-items: center; ">
|
<div style="display: flex; flex-direction: column; align-items: center; ">
|
||||||
<h2 style="font-family: Arial, Helvetica, sans-serif;">Hello from Lettre!</h2>
|
<img src="https://cdn-icons-png.flaticon.com/512/3938/3938540.png"
|
||||||
<h4 style="font-family: Arial, Helvetica, sans-serif;">A mailer library for Rust</h4>
|
style="height:100px; border-radius: 50%; background-color: whitesmoke; position: absolute; top: 40px;">
|
||||||
|
<h2 style="font-family: Arial, Helvetica, sans-serif; position: absolute; top: 160px;">Prepared with care, and sent through the horrors of the interwebs, ChronoTrack presents! (see attached)
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>"#;
|
</html>"#;
|
||||||
|
|
||||||
let email = Message::builder()
|
let email = Message::builder()
|
||||||
.from("NoReply@nickiel.net <noreply@nickiel.net>".parse().unwrap())
|
.from(match cliargs.from_addr.parse() {
|
||||||
.to(config.email_addr.parse().unwrap())
|
Ok(val) => val,
|
||||||
.subject("Testing email")
|
Err(e) => {
|
||||||
|
error!("The provided from_email address was unparsable:\n{e}");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.to(match config.email_addr.parse() {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(e) => {
|
||||||
|
error!(
|
||||||
|
"The provided destination email in the configuration file was unparsable:\n{e}"
|
||||||
|
);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.subject("ChronoTrack Export")
|
||||||
.multipart(
|
.multipart(
|
||||||
MultiPart::mixed()
|
MultiPart::mixed()
|
||||||
.multipart(
|
.multipart(
|
||||||
|
@ -392,23 +429,22 @@ fn send_email_summary(config: &Config, body_content: Vec<String>) {
|
||||||
.singlepart(
|
.singlepart(
|
||||||
SinglePart::builder()
|
SinglePart::builder()
|
||||||
.header(ContentType::TEXT_PLAIN)
|
.header(ContentType::TEXT_PLAIN)
|
||||||
.body(String::from("Hello world"))
|
.body(String::from("This is an automated email from ChronoTrack")),
|
||||||
)
|
)
|
||||||
.singlepart(
|
.singlepart(
|
||||||
SinglePart::builder()
|
SinglePart::builder()
|
||||||
.header(ContentType::TEXT_HTML)
|
.header(ContentType::TEXT_HTML)
|
||||||
.body(String::from(HTML))
|
.body(String::from(HTML)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
.singlepart(attachment),
|
||||||
)
|
)
|
||||||
.singlepart(attachment)
|
.unwrap();
|
||||||
).unwrap();
|
|
||||||
|
|
||||||
|
|
||||||
let mailer = SendmailTransport::new();
|
let mailer = SendmailTransport::new();
|
||||||
|
|
||||||
match mailer.send(&email) {
|
match mailer.send(&email) {
|
||||||
Ok(val) => debug!("email sent: {:?}", val),
|
Ok(val) => debug!("email sent: {:?}", val),
|
||||||
Err(e) => error!("Couldn't send email {}", e)
|
Err(e) => error!("Couldn't send email {}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue