Warning
It works only for students of Inha University in Tashkent!
It is nothing but a simple application written in java
that scrapes data with selenium
and notifies about the upcoming deadlines for today via telegram bot.
- Java SE-11: Language used for writing the application.
- Selenium WebDriver 4.17.0: For browser automation & scraping.
- Maven 3.6.3: Build and dependency management tool.
- WebDriver Manager 5.8.0: For automatic browser driver management (setup).
- GitHub Actions: To continiously run the project and send the output via telegram bot once a day.
Important
Actually, you don't need to install & run it locally. You just need to fork this repo on GitHub and add 4 repository secrets & create a telegram bot by yourself to get the benefit of this project. And it will itself notify you about your forthcoming deadlines for today(Assignment, Quiz, Video, which means all type of deadlines) and later (available only for videos)!
Note
When forking, do not forget to fork from the master branch as it is the one you need. In the dev branch, i usually test some modifications that may be upcoming.
These are the very 4 repository secrets:
- ID - your student ID to login (U2....).
- PASSWORD - your password for eclass.
- TELEGRAM_BOT_TOKEN - your own bot token to notify you daily about the deadlines. You get it from @BotFather after creating your bot.
- TELEGRAM_CHAT_ID - the id of your telegram chat that your bot will be sending messages in. It can be your telegram profile id or your group id - if you want to share it with your classmates as you guys have the same deadlines. If you are from CSE 22-03, you are lucky, so you don't have to worry, we are in the same group. It will be added to our telegram group, IMMEDIATELY. (upd: added✅)
Tip
For TELEGRAM_CHAT_ID, you usually get this via getUpdates()
endpoint of Telegram Bot API. But make sure to add your bot to your group, give the privilege to read messages by giving the admin rights and tag the bot and type the /start
command. Here is how you can send a request to getUpdates()
endpoint with curl:
curl -s -X GET "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates"
From the response you can get your TELEGRAM_CHAT_ID!
And if you do not change the time from the workflow file (ci-cd.yml), it will notify you around 7 am by default. If you want to change it, it is recommended to put after 7 am, which looks like this in that file:
on:
# push: # commment for easy access
# branches:
# - dev
# pull_request:
# branches:
# - master
schedule:
- cron: "0 1 * * *" # it will be 6~7 am in our timezone
1 is in GMT timezone, for customization just subtract the time you want to be notified by 5 or 6. Then the bot sends you a message like this:
-
src/main/java/eclass/kr
: Contains the main application code.DeadlineNotifier.java
: The primary class that performs the web scraping and automation tasks.Constants.java
: Contains the static variables that will never change dynamically.
-
Key methods in
DeadlineNotifier.java
:setup()
: Initializes the WebDriver and sets Chrome options.login()
: Logs into the e-class website using credentials stored in repository secrets.action()
: Retrieves and processes deadlines and event data from the page & does the whole action (mess).sleep()
: Customized (Overriden) version of Thread.sleep(long milliseconds) method.printCurrentDate()
: Prints today's date to console.parseDeadline()
: Gets the deadline string and cuts & trims & makes it 'odambashara'.printInfo()
: Prints the core message & events' list.printNoDeadlineMessage()
: naming speaks for itself!tearDown()
: Closes the WebDriver and cleans up resources.
-
.github/workflows/ci-cd.yml
:- put on scheduled cron, that runs the project at around 7 am (which you can also modify by yourself if you want) and sends a request to a telegram bot api with curl every day.
You can contribute to the project at any point! If you'd like to, please follow these steps:
-
Fork the repository
-
Clone the repository:
git clone https://github.com/<your-username>/deadline-notifier.git
-
Ensure you have the following installed:
- Java Development Kit (JDK) 8 or higher (in my case it is 11): Required to compile and run the Java code. Download jdk here.
- Maven: Build tool used to manage project dependencies and to run the application. Install Maven here.
-
Set up environment variables for login credentials:
- Create two environment variables,
ID
andPASSWORD
, that will be used for authentication for local runs:- On Windows:
setx ID "your-username" setx PASSWORD "your-password"
- On Linux/Mac (add these to your
.bashrc
or.zshrc
file):export ID=your-username export PASSWORD=your-password
- On Windows:
- Or you can just save them in your .env file, like I do in my local runs.
- Create two environment variables,
-
Install project dependencies (Maven):
- Navigate to the project directory:
cd /<your-projects-folder-name>/deadline-notifier
- Run the following command to download all required dependencies:
mvn clean install
- Navigate to the project directory:
-
WebDriver Setup:
- The project uses WebDriverManager for automatic driver management. It automatically downloads the appropriate browser driver (e.g., ChromeDriver in my case) for the version of the browser you are using. So you don't need to worry about downloading the drivers and selenium server manually.
-
Configure Chrome Options:
Tip
When running locally, do not forget to put some chrome options into a comment like this:
public static void setup() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
String arguments[] = {
"--remote-allow-origins=*",
"--no-sandbox",
"--disable-dev-shm-usage",
// "--headless",
// "--remote-debugging-port=9222"
};
options.addArguments(arguments);
driver = new ChromeDriver(options);
}
As it will allow you to see it visually running the browser, going to the eclass website, so on... By default, all of these 5 options are added since it requires the headless mode and remote debugging port when running in cloud.
-
Compile the project:
mvn compile
-
Run the project:
-
To run the project, simply execute the main class:
mvn exec:java -Dexec.mainClass="eclass.kr.DeadlineNotifier"
-
If it does not work, in the worst case, you can manually show your ID and PASSWORD variables like:
ID=<your-id> PASSWORD=<your-password> mvn exec:java -Dexec.mainClass="eclass.kr.DeadlineNotifier"
-
Verify the output:
- After running the program, the output will be displayed in the console, showing whether there are upcoming events, deadlines, and other related information.
-
-
At the end of the day, just push your changes and open a pull request to be merged.
This project is licensed under the MIT License (Modified for Non-Commercial Use). See the LICENSE file for details.