diff --git a/Cargo.lock b/Cargo.lock index db6c8be..bde719b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,9 +193,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.104" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" +checksum = "907d8581360765417f8f2e0e7d602733bbed60156b4465b7617243689ef9b83d" [[package]] name = "cfg-if" @@ -225,9 +225,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" dependencies = [ "clap_builder", "clap_derive", @@ -235,9 +235,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" dependencies = [ "anstream", "anstyle", @@ -255,7 +255,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -351,7 +351,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" dependencies = [ "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -408,7 +408,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -609,7 +609,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -841,9 +841,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.29" +version = "0.14.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" dependencies = [ "bytes", "futures-channel", @@ -865,9 +865,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4fe55fb7a772d59a5ff1dfbff4fe0258d19b89fec4b233e75d35d5d2316badc" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", @@ -891,7 +891,7 @@ checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" dependencies = [ "futures-util", "http 1.1.0", - "hyper 1.4.0", + "hyper 1.4.1", "hyper-util", "rustls", "rustls-pki-types", @@ -907,7 +907,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper 0.14.29", + "hyper 0.14.30", "native-tls", "tokio", "tokio-native-tls", @@ -921,7 +921,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.4.0", + "hyper 1.4.1", "hyper-util", "native-tls", "tokio", @@ -940,7 +940,7 @@ dependencies = [ "futures-util", "http 1.1.0", "http-body 1.0.0", - "hyper 1.4.0", + "hyper 1.4.1", "pin-project-lite", "socket2", "tokio", @@ -1283,7 +1283,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -1417,7 +1417,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -1455,7 +1455,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -1668,7 +1668,7 @@ dependencies = [ "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", - "hyper 0.14.29", + "hyper 0.14.30", "hyper-tls 0.5.0", "ipnet", "js-sys", @@ -1714,7 +1714,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.0", "http-body-util", - "hyper 1.4.0", + "hyper 1.4.1", "hyper-rustls", "hyper-tls 0.6.0", "hyper-util", @@ -1801,9 +1801,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.10" +version = "0.23.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" +checksum = "4828ea528154ae444e5a642dbb7d5623354030dc9822b83fd9bb79683c7399d0" dependencies = [ "once_cell", "rustls-pki-types", @@ -1935,22 +1935,22 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -2160,9 +2160,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" dependencies = [ "proc-macro2", "quote", @@ -2327,22 +2327,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -2378,9 +2378,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -2432,7 +2432,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -2526,7 +2526,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] @@ -2612,9 +2612,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.9.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" dependencies = [ "getrandom", ] @@ -2667,7 +2667,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", "wasm-bindgen-shared", ] @@ -2701,7 +2701,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2951,7 +2951,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.70", ] [[package]] diff --git a/src/data_backend/stuwe_parser.rs b/src/data_backend/stuwe_parser.rs index 6ca3a83..e5a6034 100644 --- a/src/data_backend/stuwe_parser.rs +++ b/src/data_backend/stuwe_parser.rs @@ -3,7 +3,7 @@ use std::vec; use crate::data_backend::{escape_markdown_v2, german_date_fmt, EMOJIS}; use crate::data_types::stuwe_data_types::{DataForMensaForDay, MealGroup, SingleMeal}; -use crate::db_operations::{get_meal_from_db, mensa_name_get_id_db, save_meal_to_db}; +use crate::db_operations::{get_jsonmeals_from_db, mensa_name_get_id_db, save_meal_to_db}; use anyhow::{anyhow, Context, Result}; use chrono::{DateTime, Datelike, Duration, Local, NaiveDate, Weekday}; @@ -102,9 +102,9 @@ pub async fn stuwe_build_meal_msg(days_forward: i64, mensa_location: u8) -> Stri async fn get_meals_from_db(requested_date: DateTime, mensa: u8) -> Vec { let date_str = build_date_string(requested_date); - let json_text = get_meal_from_db(&date_str, mensa).await.unwrap(); + let json_text = get_jsonmeals_from_db(&date_str, mensa).await.unwrap(); if let Some(json_text) = json_text { - json_to_meal(&json_text).await + json_to_meal(&json_text).await.unwrap() } else { vec![] } @@ -198,10 +198,16 @@ fn extract_mealgroup_from_htmlcontainer(meal_container: ElementRef<'_>) -> Resul let text = item.inner_html(); // for whatever reason there might be, sometimes this element exists without any content if !text.is_empty() { - item.inner_html() - .split('·') - .map(|slice| slice.trim().to_string()) - .collect() + let mut add_ingr_dedup: Vec = vec![]; + let inner_html = item.inner_html(); + let iter = inner_html.split('·').map(|slice| slice.trim().to_string()); + for ingr in iter { + if !add_ingr_dedup.contains(&ingr) { + add_ingr_dedup.push(ingr); + } + } + + add_ingr_dedup } else { // in that case, return empty vec (otherwise it would be a vec with one empty string in it) vec![] @@ -235,11 +241,14 @@ fn extract_mealgroup_from_htmlcontainer(meal_container: ElementRef<'_>) -> Resul } Some(meal_group) => { // meal group of this type already exists, add meal to it - meal_group.sub_meals.push(SingleMeal { + let add_meal = SingleMeal { name: title, price, additional_ingredients, - }); + }; + if !meal_group.sub_meals.contains(&add_meal) { + meal_group.sub_meals.push(add_meal); + } } } } @@ -325,8 +334,8 @@ pub async fn update_cache() -> Result> { Ok(mensen_today_changed) } -async fn json_to_meal(json_text: &str) -> Vec { - serde_json::from_str(json_text).unwrap() +async fn json_to_meal(json_text: &str) -> Result> { + Ok(serde_json::from_str(json_text)?) } async fn parse_and_save_meals(day: DateTime) -> Result> { @@ -341,7 +350,7 @@ async fn parse_and_save_meals(day: DateTime) -> Result> { // serialize downloaded meals for mensa_data_for_day in all_data_for_day { let downloaded_json_text = serde_json::to_string(&mensa_data_for_day.meal_groups).unwrap(); - let db_json_text = get_meal_from_db(&date_string, mensa_data_for_day.mensa_id).await?; + let db_json_text = get_jsonmeals_from_db(&date_string, mensa_data_for_day.mensa_id).await?; // if downloaded meals are different from cached meals, update cache if db_json_text.is_none() || downloaded_json_text != db_json_text.unwrap() { diff --git a/src/data_types/stuwe_data_types.rs b/src/data_types/stuwe_data_types.rs index 1cbeb78..5bdf593 100644 --- a/src/data_types/stuwe_data_types.rs +++ b/src/data_types/stuwe_data_types.rs @@ -13,7 +13,7 @@ pub struct MealGroup { pub sub_meals: Vec, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct SingleMeal { pub name: String, pub additional_ingredients: Vec, diff --git a/src/db_operations.rs b/src/db_operations.rs index 9bc88d0..8752ff3 100644 --- a/src/db_operations.rs +++ b/src/db_operations.rs @@ -178,7 +178,7 @@ pub async fn save_meal_to_db(date: &str, mensa: u8, json_text: &str) -> rusqlite Ok(()) } -pub async fn get_meal_from_db(date: &str, mensa: u8) -> rusqlite::Result> { +pub async fn get_jsonmeals_from_db(date: &str, mensa: u8) -> rusqlite::Result> { let conn = Connection::open(DB_FILENAME.get().unwrap())?; let mut stmt = conn.prepare_cached("select json_text from meals where (mensa_id, date) = (?1, ?2)")?;