Skip to main content

main/
main.rs

1use chrono::Datelike;
2use neda_lib::{
3    core::{config::Config, prayers_times::Prayers, providers::Provider},
4    providers::aladhan::AladhanProvider,
5    sound::Adhan,
6    storage::prayers_times_db::PrayersTimesDB,
7};
8
9fn main() {
10    let today = chrono::Local::now();
11    let config = Config::new(
12        today.year(),
13        today.month(),
14        today.day(),
15        "mecca".to_string(),
16        "SAU".to_string(),
17        neda_lib::core::config::GetType::Month,
18    );
19    let aladhan = AladhanProvider::new(config.clone());
20    let prayers_times = aladhan.get_prayers_times(&config).unwrap();
21    // println!("prayers_times is: {:#?}", prayers_times);
22
23    let db = PrayersTimesDB::new("lib/local.db".to_string());
24    match db {
25        Ok(mut db) => {
26            match db.push(&prayers_times) {
27                Ok(_) => {
28                    println!("ignore pushing to the db");
29                }
30                _ => {
31                    println!("pushing to the db");
32                }
33            };
34
35            let day_salawat = db.get_day_times(&prayers_times.from).unwrap();
36            let fjer = db.get_prayer_time(Prayers::Fajr, &prayers_times.from);
37            println!("fjer is: {:#?}", fjer);
38            println!("day salawat is: {:#?}", day_salawat);
39            // let's run the adhan now
40            let adhan = Adhan::new("lib/examples/audio/اذان-احمد-النفيس.mp3".to_string());
41            adhan.play();
42        }
43        Err(e) => {
44            println!("Error: {:#?}", e);
45        }
46    }
47}