From 4a9b55b2db83869a27b3dca4f04e0e805feb31ca Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Wed, 24 Sep 2025 11:14:53 +0200 Subject: [PATCH] log to stderr + fetch up to 30 days in future --- README.md | 2 +- src/main.rs | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b21627a..95ced4c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Fetches upcoming menu (14 days) from Komida JSON API and converts it to `.ics` ([iCalendar](https://icalendar.org/)) format, to be imported into e.g., Google Calendar. Hardcoded features: - - fetches up to 14 days in the future + - fetches up to 30 days in the future - only creates calendar items for: - daily menu - "street food" diff --git a/src/main.rs b/src/main.rs index b35448b..c1dc5d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ use serde::Deserialize; use icalendar::Component; use icalendar::EventLike; -const location_id: &str = "8199"; // Middelheim? -const customer_id: &str = "7622"; // Me? +const LOCATION_ID: &str = "8199"; // Middelheim? +const CUSTOMER_ID: &str = "7622"; // Me? #[derive(Deserialize)] struct MenuItem { @@ -29,22 +29,26 @@ fn main() -> Result<(), Box> { calendar.name("Komida Menu"); - for days_in_future in 0..14 { + for days_in_future in 0..30 { let date = now + chrono::Days::new(days_in_future); // komida API expects local time let date_komida_fmt = date.format("%Y-%m-%d"); - let res: Response = get(format!( + let url = format!( "https://app.growzer.be/MenuPlanner/GetMenuPlanner?locationId={}&stringDate={}&customerId={}", - location_id, + LOCATION_ID, date_komida_fmt, - customer_id, - ))?.json()?; + CUSTOMER_ID, + ); + + eprintln!("fetching: {url}"); + + let res: Response = get(url)?.json()?; // ical uses UTC - let lunch_starts_at = date.with_time(chrono::NaiveTime::from_hms(11, 30, 00)).unwrap().to_utc(); - let lunch_ends_at = date.with_time(chrono::NaiveTime::from_hms(13, 45, 00)).unwrap().to_utc(); + let lunch_starts_at = date.with_time(chrono::NaiveTime::from_hms_opt(11, 30, 00).unwrap()).unwrap().to_utc(); + let lunch_ends_at = date.with_time(chrono::NaiveTime::from_hms_opt(13, 45, 00).unwrap()).unwrap().to_utc(); for item in res.data.menuPlannerList.iter() { if item.SectionName.contains("Streetfood")