diff --git a/Cargo.lock b/Cargo.lock index cce56ba..c243cc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2265,7 +2265,6 @@ dependencies = [ "reqwest-websocket", "rusqlite", "scraper", - "selectors", "serde", "serde_json", "static_init", diff --git a/Cargo.toml b/Cargo.toml index a779470..9fd0247 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ reqwest = { version = "0.12.2", features = ["cookies", "json"] } reqwest-websocket = "0.4.2" rusqlite = { version = "0.32.1" } scraper = "0.20.0" -selectors = "0.25.0" serde = { version = "1.0.196", features = ["derive"] } serde_json = "1.0.113" static_init = "1.0.3" diff --git a/README.md b/README.md index a67071d..bb3552c 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,6 @@ A Telegram bot that crawls the Studentenwerk Leipzig Mensa site and returns toda ## Runtime Dependencies * A Bot has to be created using [@BotFather](https://t.me/BotFather), which produces a Token +* An instance of (Mensa-API)[https://github.com/greybaron/mensa-api] has to be running. The API url must be passed, for example `API_URL=http://url:9090`. Can be set by env variable or launch argument, run this program with option `-h` for details. ℹ️ There is a branch "standalone" which doesn't need this API, however it won't receive further updates. * If using the CampusDual feature, the `GEANT OV RSA CA 4` certificate must be installed. On most Linux distributions, this certificate is not shipped * Any data that is persisted is saved to SQLite3 databases in the current working directory, so it should be ensured that the directory is writable and not volatile diff --git a/src/bin/mensi-telegram-bin.rs b/src/bin/mensi-telegram-bin.rs index ae25908..73cffd6 100644 --- a/src/bin/mensi-telegram-bin.rs +++ b/src/bin/mensi-telegram-bin.rs @@ -15,7 +15,7 @@ use stuwe_telegram_rs::data_types::{ Backend, Command, DialogueState, JobHandlerTask, JobHandlerTaskType, JobType, QueryRegistrationType, RegistrationEntry, }; -use stuwe_telegram_rs::db_operations::{check_or_create_db_tables, init_mensa_id_db}; +use stuwe_telegram_rs::db_operations::check_or_create_db_tables; use stuwe_telegram_rs::shared_main::callback_handler; use stuwe_telegram_rs::task_scheduler_funcs::{ handle_add_registration_task, handle_delete_registration_task, handle_query_registration_task, @@ -94,7 +94,6 @@ async fn main() { check_or_create_db_tables().unwrap(); let mensen = get_mensen().await.unwrap(); - init_mensa_id_db(&mensen).unwrap(); let bot = Bot::new(args.token); diff --git a/src/bin/stuwe-telegram-bin.rs b/src/bin/stuwe-telegram-bin.rs index e59c1d0..80d6bcb 100644 --- a/src/bin/stuwe-telegram-bin.rs +++ b/src/bin/stuwe-telegram-bin.rs @@ -14,7 +14,7 @@ use stuwe_telegram_rs::data_types::{ Backend, Command, DialogueState, JobHandlerTask, JobHandlerTaskType, JobType, QueryRegistrationType, RegistrationEntry, }; -use stuwe_telegram_rs::db_operations::{check_or_create_db_tables, init_mensa_id_db}; +use stuwe_telegram_rs::db_operations::check_or_create_db_tables; use stuwe_telegram_rs::shared_main::callback_handler; use stuwe_telegram_rs::task_scheduler_funcs::{ handle_add_registration_task, handle_broadcast_update_task, handle_delete_registration_task, @@ -97,7 +97,6 @@ async fn main() { check_or_create_db_tables().unwrap(); let mensen = get_mensen().await.unwrap(); - init_mensa_id_db(&mensen).unwrap(); let bot = Bot::new(args.token); diff --git a/src/db_operations.rs b/src/db_operations.rs index dbfc090..8f3d878 100644 --- a/src/db_operations.rs +++ b/src/db_operations.rs @@ -1,5 +1,5 @@ use rusqlite::{params, Connection}; -use std::{collections::BTreeMap, process::exit}; +use std::process::exit; use crate::{ constants::DB_FILENAME, @@ -74,40 +74,6 @@ pub fn check_or_create_db_tables() -> rusqlite::Result<()> { )? .execute([])?; - // table of all mensa names - conn.prepare( - "create table if not exists mensen ( - mensa_id integer primary key, - mensa_name text not null unique - )", - )? - .execute([])?; - - // table of all meals - conn.prepare( - "create table if not exists meals ( - mensa_id integer, - date text, - json_text text, - foreign key (mensa_id) references mensen(mensa_id) - )", - )? - .execute([])?; - - Ok(()) -} - -pub fn init_mensa_id_db(mensen: &BTreeMap) -> rusqlite::Result<()> { - let conn = Connection::open(DB_FILENAME.get().unwrap())?; - let mut stmt = conn.prepare_cached( - "replace into mensen (mensa_id, mensa_name) - values (?1, ?2)", - )?; - - for (id, name) in mensen.iter() { - stmt.execute(params![id.to_string(), name])?; - } - Ok(()) } diff --git a/src/task_scheduler_funcs.rs b/src/task_scheduler_funcs.rs index d8ba96c..80fac2f 100644 --- a/src/task_scheduler_funcs.rs +++ b/src/task_scheduler_funcs.rs @@ -245,7 +245,6 @@ pub async fn start_mensaupd_hook_and_campusdual_job( let bot = bot.clone(); Box::pin(async move { - log::info!("Updating CampusDual"); check_notify_campusdual_grades_signups(bot).await; }) }) @@ -279,6 +278,7 @@ pub async fn await_handle_mealplan_upd(job_handler_tx: Sender) - async fn check_notify_campusdual_grades_signups(bot: Bot) { if let Some(cd_data) = CD_DATA.get() { + log::info!("Updating CampusDual"); match get_campusdual_data(cd_data.username.clone(), cd_data.password.clone()).await { Ok((grades, signup_options)) => { if let Some(new_grades) = compare_campusdual_grades(&grades).await {