Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update readme, delete unused stuff #10

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/bin/mensi-telegram-bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/bin/stuwe-telegram-bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
36 changes: 1 addition & 35 deletions src/db_operations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rusqlite::{params, Connection};
use std::{collections::BTreeMap, process::exit};
use std::process::exit;

use crate::{
constants::DB_FILENAME,
Expand Down Expand Up @@ -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<u8, String>) -> 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(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/task_scheduler_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
})
Expand Down Expand Up @@ -279,6 +278,7 @@ pub async fn await_handle_mealplan_upd(job_handler_tx: Sender<JobHandlerTask>) -

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 {
Expand Down