forked from jelson.rodrigues/piperun-bot
adicao da entrada do dia para avaliar
This commit is contained in:
79
src/main.rs
79
src/main.rs
@@ -183,6 +183,53 @@ fn main() -> anyhow::Result<()> {
|
||||
.expect("Failed to response_time.csv");
|
||||
}
|
||||
|
||||
/*
|
||||
// --- NOVO: processar argumento de linha de comando para data específica ---
|
||||
use std::env;
|
||||
use chrono::NaiveDate;
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let target_day = if args.len() > 1 {
|
||||
// Se um argumento foi passado, interpretar como YYYY-MM-DD
|
||||
let naive_date = NaiveDate::parse_from_str(&args[1], "%Y-%m-%d")
|
||||
.expect("Formato de data inválido. Use YYYY-MM-DD");
|
||||
// Converter para DateTime com hora 00:00:00 do fuso local
|
||||
naive_date.and_hms_opt(0, 0, 0).unwrap()
|
||||
} else {
|
||||
// Comportamento padrão: dia anterior ao atual
|
||||
(chrono::Local::now() - chrono::Duration::days(1)).naive_local()
|
||||
};
|
||||
|
||||
println!("Processando o dia: {}", target_day.format("%Y-%m-%d"));
|
||||
|
||||
// Definir início e fim do dia (para consultas na API)
|
||||
let day_start = target_day; // já 00:00
|
||||
let day_end = target_day
|
||||
.with_hour(23).unwrap()
|
||||
.with_minute(59).unwrap()
|
||||
.with_second(59).unwrap();
|
||||
|
||||
let formatted_day = target_day.format("%Y-%m-%d").to_string();
|
||||
let formatted_day_start = day_start.format("%Y-%m-%d %H:%M").to_string();
|
||||
let formatted_day_end = day_end.format("%Y-%m-%d %H:%M").to_string();
|
||||
|
||||
println!("Início do dia: {}", formatted_day_start);
|
||||
println!("Fim do dia: {}", formatted_day_end);
|
||||
|
||||
// Criar pasta com o nome do dia processado
|
||||
if !std::fs::exists(format!("./evaluations/{formatted_day}")).unwrap() {
|
||||
std::fs::create_dir(format!("./evaluations/{formatted_day}"))
|
||||
.expect("Failed to create directory");
|
||||
}
|
||||
|
||||
// Criar arquivo response_time.csv se não existir
|
||||
if !std::fs::exists(format!("./evaluations/{formatted_day}/response_time.csv")).unwrap() {
|
||||
let _ = std::fs::File::create_new(format!(
|
||||
"./evaluations/{formatted_day}/response_time.csv"
|
||||
))
|
||||
.expect("Failed to create response_time.csv");
|
||||
}
|
||||
*/
|
||||
// Read system prompt
|
||||
let prompt = std::fs::read_to_string("PROMPT.txt").unwrap();
|
||||
let filter_file_contents = std::fs::read_to_string("FILTER.txt").unwrap_or(String::new());
|
||||
@@ -196,7 +243,9 @@ fn main() -> anyhow::Result<()> {
|
||||
&client,
|
||||
&access_token,
|
||||
formatted_day_before_at_midnight,
|
||||
//formatted_day_start,
|
||||
formatted_day_before_at_23_59_59,
|
||||
//formatted_day_end,
|
||||
);
|
||||
|
||||
println!("Number of consolidated talks: {}", talks_array.len());
|
||||
@@ -424,6 +473,7 @@ fn main() -> anyhow::Result<()> {
|
||||
.write(true)
|
||||
.open(format!(
|
||||
"./evaluations/{formatted_day_before}/response_time.csv"
|
||||
//"./evaluations/{formatted_day}/response_time.csv"
|
||||
))
|
||||
.expect("Failed to open response time file for write");
|
||||
response_time_file
|
||||
@@ -502,6 +552,7 @@ fn main() -> anyhow::Result<()> {
|
||||
format!(
|
||||
"./evaluations/{}/{} - {} - {}.csv",
|
||||
formatted_day_before, user_name, talk_id, tracking_number
|
||||
//formatted_day, user_name, talk_id, tracking_number
|
||||
),
|
||||
csv_response,
|
||||
)
|
||||
@@ -510,6 +561,7 @@ fn main() -> anyhow::Result<()> {
|
||||
format!(
|
||||
"./evaluations/{}/{} - {} - {} - prompt.txt",
|
||||
formatted_day_before, user_name, talk_id, tracking_number
|
||||
//formatted_day, user_name, talk_id, tracking_number
|
||||
),
|
||||
format!("{prompt} \n{talk}"),
|
||||
)
|
||||
@@ -523,22 +575,25 @@ fn main() -> anyhow::Result<()> {
|
||||
|
||||
// Compress folder into zip
|
||||
let source_dir_str = format!("./evaluations/{formatted_day_before}");
|
||||
//let source_dir_str = format!("./evaluations/{formatted_day}");
|
||||
let output_zip_file_str = format!("./evaluations/{formatted_day_before}.zip");
|
||||
//let output_zip_file_str = format!("./evaluations/{formatted_day}.zip");
|
||||
let source_dir = std::path::Path::new(source_dir_str.as_str());
|
||||
let output_zip_file = std::path::Path::new(output_zip_file_str.as_str());
|
||||
zip_directory_util::zip_directory_util::zip_source_dir_to_dst_file(source_dir, output_zip_file);
|
||||
|
||||
// Send folder to email
|
||||
// let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, Isadora G. Moura de Moura <isadora.moura@nova.net.br>";
|
||||
// println!("Trying to send email... Recipients {recipients}");
|
||||
let recipients = "nicolas.borges@nova.net.br, Isadora G. Moura de Moura <isadora.moura@nova.net.br>";
|
||||
println!("Trying to send email... Recipients {recipients}");
|
||||
|
||||
// send_mail_util::send_mail_util::send_email(
|
||||
// &format!("Avaliacao atendimentos {formatted_day_before}"),
|
||||
// &BOT_EMAIL,
|
||||
// &BOT_EMAIL_PASSWORD,
|
||||
// recipients,
|
||||
// &output_zip_file_str,
|
||||
// );
|
||||
send_mail_util::send_mail_util::send_email(
|
||||
&format!("Avaliacao atendimentos {formatted_day_before}"),
|
||||
//&format!("Avaliacao atendimentos {formatted_day}"),
|
||||
&BOT_EMAIL,
|
||||
&BOT_EMAIL_PASSWORD,
|
||||
recipients,
|
||||
&output_zip_file_str,
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@@ -548,7 +603,9 @@ fn get_piperun_chats_on_date(
|
||||
client: &reqwest::blocking::Client,
|
||||
access_token: &String,
|
||||
formatted_day_before_at_midnight: String,
|
||||
//formatted_day_start: String,
|
||||
formatted_day_before_at_23_59_59: String,
|
||||
//formatted_day_end: String,
|
||||
) -> Vec<serde_json::Value> {
|
||||
let start_of_talk_code: String = "talk_start".to_string();
|
||||
let support_queue_id: String = "13".to_string();
|
||||
@@ -568,7 +625,9 @@ fn get_piperun_chats_on_date(
|
||||
("perPage", per_page.clone()),
|
||||
("report_type", report_type.clone()),
|
||||
("start_date", formatted_day_before_at_midnight.clone()),
|
||||
//("start_date", formatted_day_start.clone()),
|
||||
("end_date", formatted_day_before_at_23_59_59.clone()),
|
||||
//("end_date", formatted_day_end.clone()),
|
||||
("date_range_type", start_of_talk_code.clone()),
|
||||
("queue_id[]", support_queue_id.clone()),
|
||||
]);
|
||||
@@ -624,7 +683,9 @@ fn get_piperun_chats_on_date(
|
||||
("perPage", per_page.clone()),
|
||||
("report_type", report_type.clone()),
|
||||
("start_date", formatted_day_before_at_midnight.clone()),
|
||||
//("start_date", formatted_day_start.clone()),
|
||||
("end_date", formatted_day_before_at_23_59_59.clone()),
|
||||
//("end_date", formatted_day_end.clone()),
|
||||
("date_range_type", start_of_talk_code.clone()),
|
||||
("queue_id[]", support_queue_id.clone()),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user