From d495acfc9dd085ac483b14f6483eb68f95832e3e Mon Sep 17 00:00:00 2001 From: Nulo Date: Sun, 23 Jun 2024 14:06:50 -0300 Subject: [PATCH] error when error in best selling --- scraper-rs/src/auto.rs | 22 ++++++++++++++++++++++ scraper-rs/src/main.rs | 8 +------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/scraper-rs/src/auto.rs b/scraper-rs/src/auto.rs index 9ba16f9..36862aa 100644 --- a/scraper-rs/src/auto.rs +++ b/scraper-rs/src/auto.rs @@ -2,6 +2,7 @@ use super::now_sec; use super::supermercado::Supermercado; use super::AutoArgs; use super::AutoTelegram; +use crate::best_selling; use crate::db::Db; use crate::scraper::Scraper; use futures::Future; @@ -70,6 +71,27 @@ impl Auto { Ok(()) } + pub async fn download_best_selling(&self) -> anyhow::Result<()> { + // let best_selling: Vec = + + match self + .inform_time( + "Downloaded best selling", + best_selling::get_all_best_selling(&self.db), + ) + .await + { + Ok(best_selling) => { + self.db.save_best_selling(best_selling).await?; + } + Err(err) => { + self.inform(&format!("FAILED best selling: {:?}", err)) + .await + } + } + Ok(()) + } + pub async fn inform_time, R>(&self, msg: &str, action: T) -> R { let t0 = now_sec(); let res = action.await; diff --git a/scraper-rs/src/main.rs b/scraper-rs/src/main.rs index 3571793..8ee8854 100644 --- a/scraper-rs/src/main.rs +++ b/scraper-rs/src/main.rs @@ -256,13 +256,7 @@ async fn auto_cli(args: AutoArgs) -> anyhow::Result<()> { future::try_join_all(handles).await?; auto.inform("[auto] Download supermercados finished").await; - let best_selling = auto - .inform_time( - "Downloaded best selling", - best_selling::get_all_best_selling(&auto.db), - ) - .await?; - auto.db.save_best_selling(best_selling).await?; + auto.download_best_selling().await?; Ok(()) }