2021-03-01 23:39:16 +01:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use my_tasks::{client::Client, traits::CalDavSource};
|
|
|
|
use my_tasks::cache::Cache;
|
|
|
|
use my_tasks::Provider;
|
2021-02-24 23:49:20 +01:00
|
|
|
use my_tasks::settings::URL;
|
|
|
|
use my_tasks::settings::USERNAME;
|
|
|
|
use my_tasks::settings::PASSWORD;
|
|
|
|
|
2021-03-31 08:32:28 +02:00
|
|
|
const CACHE_FOLDER: &str = "example_cache";
|
|
|
|
|
2021-03-01 23:39:16 +01:00
|
|
|
|
2021-02-24 23:49:20 +01:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2021-03-31 08:32:28 +02:00
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
let cache_path = Path::new(CACHE_FOLDER);
|
2021-02-24 23:49:20 +01:00
|
|
|
|
2021-03-31 08:32:28 +02:00
|
|
|
let client = Client::new(URL, USERNAME, PASSWORD).unwrap();
|
|
|
|
let cache = match Cache::from_folder(&cache_path) {
|
2021-03-01 23:39:16 +01:00
|
|
|
Ok(cache) => cache,
|
|
|
|
Err(err) => {
|
|
|
|
log::warn!("Invalid cache file: {}. Using a default cache", err);
|
|
|
|
Cache::new(&cache_path)
|
|
|
|
}
|
|
|
|
};
|
2021-03-31 08:32:28 +02:00
|
|
|
let mut provider = Provider::new(client, cache);
|
2021-03-01 23:39:16 +01:00
|
|
|
|
|
|
|
let cals = provider.local().get_calendars().await.unwrap();
|
|
|
|
println!("---- before sync -----");
|
2021-03-31 08:32:28 +02:00
|
|
|
my_tasks::utils::print_calendar_list(&cals).await;
|
2021-03-01 23:39:16 +01:00
|
|
|
|
2021-03-31 08:32:28 +02:00
|
|
|
if let Err(err) = provider.sync().await {
|
|
|
|
log::error!("Unable to sync: {}", err);
|
|
|
|
}
|
2021-03-01 23:39:16 +01:00
|
|
|
println!("---- after sync -----");
|
2021-03-31 08:32:28 +02:00
|
|
|
let cals = provider.local().get_calendars().await.unwrap();
|
|
|
|
my_tasks::utils::print_calendar_list(&cals).await;
|
2021-02-24 23:49:20 +01:00
|
|
|
}
|