diff --git a/Cargo.lock b/Cargo.lock index d03e3bd..8e4874c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,9 +156,11 @@ dependencies = [ "clap", "csv", "directories", + "env_logger", "futures", "icalendar", "libxml", + "log", "regex", "reqwest", "rusty-hook", @@ -273,6 +275,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_logger" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "envmnt" version = "0.8.4" @@ -512,6 +527,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.20" diff --git a/Cargo.toml b/Cargo.toml index 7a7aafe..94401d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,9 @@ features = ["cargo"] [dependencies.directories] version = "4.0" +[dependencies.env_logger] +version = "0.9" + [dependencies.futures] version = "0.3" @@ -47,6 +50,9 @@ features = ["parser"] [dependencies.libxml] version = "0.3" +[dependencies.log] +version = "0.4" + [dependencies.regex] version = "1.6" diff --git a/src/commands/groceries.rs b/src/commands/groceries.rs index 7ddbd56..bb70118 100644 --- a/src/commands/groceries.rs +++ b/src/commands/groceries.rs @@ -25,7 +25,7 @@ pub async fn with( let ingredients = get_ingredients(api_client, ids).await?; let ingredients = merge_ingredients(ingredients); let md = prepare_grocery_list(&ingredients)?; - // TODO filename is hardcoded for now + log::debug!("Saving the following grocery list:\n\n{}", &md); save_grocery_list(api_client, location, &md).await?; Ok(()) } @@ -71,7 +71,10 @@ where .await .expect(&format!("Cannot fetch recipe with id {}", id)); - response.json::().await.map(|r| r.ingredients) + response.json::().await.map(|r| { + log::info!("Retrieved ingredients for '{}'", r.name); + r.ingredients + }) }); let ingredients = futures::future::try_join_all(ingredients).await?; @@ -138,6 +141,7 @@ async fn save_grocery_list(api_client: &ApiClient, filename: &str, contents: &st })?; let file_url = dav_base_url.join(filename).unwrap(); + log::info!("Saving grocery list to {}", &file_url); let response = api_client .rest() .put(file_url.clone()) diff --git a/src/commands/import.rs b/src/commands/import.rs index f7c0e82..347dbb2 100644 --- a/src/commands/import.rs +++ b/src/commands/import.rs @@ -24,6 +24,7 @@ where response.status() ); } + log::info!("Imported recipe into cookbook: {}", url.as_ref()); } Ok(()) diff --git a/src/commands/schedule_csv.rs b/src/commands/schedule_csv.rs index f63ae7a..b160b8d 100644 --- a/src/commands/schedule_csv.rs +++ b/src/commands/schedule_csv.rs @@ -31,6 +31,9 @@ pub async fn with(api_client: &ApiClient, calendar: &str, csv_file: &Path) -> Re let recipe_urls = urls_from_csv(records.iter())?; import::with(&api_client, recipe_urls.into_iter()).await?; + + // Unfortunately, Nextcloud Cookbook doesn't return an id for imported recipes, + // so we have to resort to fetch all of them to match them let recipes = get_all_recipes(&api_client).await?; let events = records @@ -70,6 +73,7 @@ where } async fn get_all_recipes(api_client: &ApiClient) -> Result>> { + log::info!("Getting list of all recipes"); let metadata = api_client .rest() .get(api_client.base_url().join("apps/cookbook/api/recipes")?) @@ -130,6 +134,11 @@ where &helpers::ical_escape_text(&ev.recipe.name) ); + log::info!( + "Saving event at {} for '{}'", + &ev.ends_at.date(), + &ev.recipe.name + ); let cal = icalendar::Calendar::new() .push::(ev.into()) .done(); diff --git a/src/main.rs b/src/main.rs index d9ec382..daa8691 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,8 @@ use { #[tokio::main(flavor = "multi_thread")] async fn main() -> Result<()> { + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); + let args = setup_args(); parse_args(&args).await }