Add some logging
This commit is contained in:
parent
7f48c6cfa4
commit
9ccec9878a
6 changed files with 45 additions and 2 deletions
|
@ -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::<Recipe>().await.map(|r| r.ingredients)
|
||||
response.json::<Recipe>().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())
|
||||
|
|
|
@ -24,6 +24,7 @@ where
|
|||
response.status()
|
||||
);
|
||||
}
|
||||
log::info!("Imported recipe into cookbook: {}", url.as_ref());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -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<HashMap<String, Rc<recipe::Recipe>>> {
|
||||
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::<icalendar::Event>(ev.into())
|
||||
.done();
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue