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(()) }