use std::sync::LazyLock; use anyhow::Result; use chrono::{Duration, Utc}; use futures::{future, StreamExt}; use mensa_upb_scraper::{check_refresh, util, FILTER_CANTEENS}; use shared::Canteen; use strum::IntoEnumIterator as _; use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; static CANTEENS: LazyLock> = LazyLock::new(|| { Canteen::iter() .filter(|c| !FILTER_CANTEENS.contains(c)) .collect::>() }); #[tokio::main] async fn main() -> Result<()> { dotenvy::dotenv().ok(); let db = util::get_db()?; let env_filter = EnvFilter::builder() .with_default_directive(LevelFilter::WARN.into()) .from_env() .expect("Invalid filter") .add_directive("mensa_upb_scraper=debug".parse().unwrap()); tracing_subscriber::fmt().with_env_filter(env_filter).init(); sqlx::migrate!("../migrations").run(&db).await?; tracing::info!("Starting up..."); let handles = (0..7) .map(|d| (Utc::now() + Duration::days(d)).date_naive()) .map(|date| { let db = db.clone(); tokio::spawn(async move { check_refresh(&db, date, &CANTEENS).await }) }); future::join_all(handles).await; futures::stream::iter((0..7).map(|d| (Utc::now() + Duration::days(d)).date_naive())) .for_each_concurrent(None, async |date| { check_refresh(&db, date, &CANTEENS).await; }) .await; tracing::info!("Finished scraping menu"); Ok(()) }