log to stderr + fetch up to 30 days in future
This commit is contained in:
parent
4b60499e49
commit
4a9b55b2db
2 changed files with 14 additions and 10 deletions
|
|
@ -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.
|
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:
|
Hardcoded features:
|
||||||
- fetches up to 14 days in the future
|
- fetches up to 30 days in the future
|
||||||
- only creates calendar items for:
|
- only creates calendar items for:
|
||||||
- daily menu
|
- daily menu
|
||||||
- "street food"
|
- "street food"
|
||||||
|
|
|
||||||
22
src/main.rs
22
src/main.rs
|
|
@ -3,8 +3,8 @@ use serde::Deserialize;
|
||||||
use icalendar::Component;
|
use icalendar::Component;
|
||||||
use icalendar::EventLike;
|
use icalendar::EventLike;
|
||||||
|
|
||||||
const location_id: &str = "8199"; // Middelheim?
|
const LOCATION_ID: &str = "8199"; // Middelheim?
|
||||||
const customer_id: &str = "7622"; // Me?
|
const CUSTOMER_ID: &str = "7622"; // Me?
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct MenuItem {
|
struct MenuItem {
|
||||||
|
|
@ -29,22 +29,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
calendar.name("Komida Menu");
|
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);
|
let date = now + chrono::Days::new(days_in_future);
|
||||||
|
|
||||||
// komida API expects local time
|
// komida API expects local time
|
||||||
let date_komida_fmt = date.format("%Y-%m-%d");
|
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={}",
|
"https://app.growzer.be/MenuPlanner/GetMenuPlanner?locationId={}&stringDate={}&customerId={}",
|
||||||
location_id,
|
LOCATION_ID,
|
||||||
date_komida_fmt,
|
date_komida_fmt,
|
||||||
customer_id,
|
CUSTOMER_ID,
|
||||||
))?.json()?;
|
);
|
||||||
|
|
||||||
|
eprintln!("fetching: {url}");
|
||||||
|
|
||||||
|
let res: Response = get(url)?.json()?;
|
||||||
|
|
||||||
// ical uses UTC
|
// ical uses UTC
|
||||||
let lunch_starts_at = date.with_time(chrono::NaiveTime::from_hms(11, 30, 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(13, 45, 00)).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() {
|
for item in res.data.menuPlannerList.iter() {
|
||||||
if item.SectionName.contains("Streetfood")
|
if item.SectionName.contains("Streetfood")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue