birthday-reminder/main.rs
2021-09-17 17:57:48 +02:00

40 lines
998 B
Rust

use chrono::*; // For date
use std::fs; // To list files
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
fn birthdate (filename: String) -> String {
let file = File::open(filename).expect("file not found!");
let reader = BufReader::new(file);
for line in reader.lines() {
let l:String = line.unwrap();
if l.starts_with("BDAY") {
return l[5..].to_string();
}
}
return "".to_string()
}
fn main() {
/* Where are the vcf files */
let vcf_dir = "/home/ilya/.contacts/contacts";
/* How much day before */
let delta_d:u8 = 10;
let now = Local::now();
let paths = fs::read_dir(vcf_dir).unwrap();
for path in paths {
let filename :String = path.unwrap().path().into_os_string().into_string().unwrap();
let bdate:String = birthdate(filename);
if bdate == "" {
continue
}
//println!("{}", bdate);
println!("{}",UTC::Date(bdate));
}
}