Skip to content

Add New Alert System for Train Search Results with Enhanced Scheduling#20

Open
davidmohedanovazquez wants to merge 6 commits intoemartinez-dev:masterfrom
davidmohedanovazquez:master
Open

Add New Alert System for Train Search Results with Enhanced Scheduling#20
davidmohedanovazquez wants to merge 6 commits intoemartinez-dev:masterfrom
davidmohedanovazquez:master

Conversation

@davidmohedanovazquez
Copy link

This pull request introduces a new alert system for train search results and includes several changes to support this feature. The most important changes are the addition of functions to handle loading and comparing search results, scheduling alerts, and managing alert states.

Alert System Implementation:

  • bot/utils.py: Added load_last_search_results and compare_search_results functions to handle loading previous search results from a file and comparing them with current results.

  • renfe-bot.py: Added new command handlers for /alert and /shutdown_alert to configure and manage search alerts. [1] [2]

Scheduling and Alert Management:

  • renfe-bot.py: Integrated the schedule library to set up periodic tasks for checking search results changes. Added schedule_alerts, get_alert_frequency, and check_for_changes functions to handle the scheduling logic and alert checks. [1] [2]

Search Function Enhancements:

  • renfe-bot.py: Modified the search_trains function to handle scheduled tasks and save search results to a file. [1] [2]

…all cases

* Add parameter `is_scheduled_task` to `search_trains` function in `renfe-bot.py`
* Modify `search_trains` function to check if results are empty and send a message to Telegram if no trains are found
* Modify `check_for_changes` function to check if results are empty and avoid generating an exception
* Add a check in the `/alert` command handler to verify the existence of `last_input.json` and `last_search_results.json` files before proceeding
* Add a message to inform the user to perform a search first if the files do not exist
* Modify the `/shutdown_alert` command handler to check if `alerting` is already `False` and inform the user that no alerts were configured if so
@emartinez-dev emartinez-dev self-requested a review November 20, 2024 21:11
@emartinez-dev
Copy link
Owner

Hey @davidmohedanovazquez, thank you for your work!

The Renfe website changed so much in the last year that the latest version of the bot is barely usable, as both the scraper and the functions to make the query for the train tickets are not working right now.

I will try to address all the problems that the bot has now before merging your alert system, which I find very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants