Skip to content

holocen/esdnevnik-tracker

Repository files navigation

📚 esDnevnik Tracker

Node.js Playwright License: MIT Windows

esdnevnik-tracker is a Windows-first Node.js script that logs in to esDnevnik with Playwright, collects graded tasks, upcoming tasks, and recent dashboard grades, writes a local Markdown report, and sends a Telegram summary.

The project was built and tested in a Windows workflow and runs with plain Node.js, Playwright, and node-fetch@2; OpenClaw was part of the build and debugging workflow, not a runtime dependency.

✨ Features

  • Login automation for https://moj.esdnevnik.rs.
  • Graded task scraping with grade and grading date extraction.
  • Upcoming task scraping with date, type, subject, and note extraction.
  • Recent grade scraping from dashboard timeline items.
  • Markdown report generation for local storage.
  • Telegram delivery with automatic split when the message becomes too long for a single Telegram message.
  • Weekday-only sending plus a once-per-day guard using last_sent.txt.

🧰 Stack

  • Node.js
  • Playwright
  • node-fetch@2
  • Telegram Bot API

node-fetch@2 is used because the script relies on the CommonJS require('node-fetch') pattern, which matches v2 and can conflict with newer ESM-only versions.

📁 Project structure

Typical repository contents:

  • extractGrades.js — main script
  • package.json — project metadata and dependencies
  • package-lock.json — dependency lockfile
  • README.md — project documentation
  • LICENSE — project license
  • Screenshot_Telegram.jpg — example Telegram output

⚙️ Installation

Install dependencies:

npm install playwright node-fetch@2
npx playwright install chromium

🔐 Configuration

The script uses Windows user-level configuration stored in the registry-backed user environment.

Required values

The current public-safe script expects these runtime values:

  • ESDNEVNIK_USER
  • ESDNEVNIK_PASS
  • TELEGRAM_BOT_TOKEN
  • TELEGRAM_CHAT_ID

Registry commands

Store the values in HKCU\Environment with reg.exe:

reg add HKCU\Environment /v ESDNEVNIK_USER /t REG_SZ /d "your_esdnevnik_username" /f
reg add HKCU\Environment /v ESDNEVNIK_PASS /t REG_SZ /d "your_esdnevnik_password" /f
reg add HKCU\Environment /v TELEGRAM_BOT_TOKEN /t REG_SZ /d "your_telegram_bot_token" /f
reg add HKCU\Environment /v TELEGRAM_CHAT_ID /t REG_SZ /d "your_telegram_chat_id" /f

Open a new PowerShell window after writing the values so new processes can read them.

Verify stored values

[Environment]::GetEnvironmentVariable("ESDNEVNIK_USER", "User")
[Environment]::GetEnvironmentVariable("ESDNEVNIK_PASS", "User")
[Environment]::GetEnvironmentVariable("TELEGRAM_BOT_TOKEN", "User")
[Environment]::GetEnvironmentVariable("TELEGRAM_CHAT_ID", "User")

🤖 Telegram bot setup

This project sends notifications through the Telegram Bot API.

1. Create a bot

Open Telegram, search for @BotFather, start a chat, and run:

/newbot

Follow the prompts to choose:

  • a bot name
  • a bot username ending with bot

BotFather will return a bot token. Save that value and use it as TELEGRAM_BOT_TOKEN.

2. Start a chat with the bot

Open the newly created bot in Telegram and send it at least one message, for example:

/start

This step is important because the bot needs a chat history before getUpdates can return the chat ID.

3. Get the chat ID

Open this URL in a browser and replace YOUR_BOT_TOKEN with the real token:

https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates

In the JSON response, find:

"chat": {
  "id": 123456789
}

That number is the value for TELEGRAM_CHAT_ID.

4. Store the values

Save both values with the registry commands shown in the Configuration section:

  • TELEGRAM_BOT_TOKEN
  • TELEGRAM_CHAT_ID

5. Test the bot manually

Browser test:

https://api.telegram.org/botYOUR_BOT_TOKEN/sendMessage?chat_id=YOUR_CHAT_ID&text=Telegram%20bot%20test

PowerShell test:

Invoke-RestMethod -Uri "https://api.telegram.org/botYOUR_BOT_TOKEN/sendMessage" `
  -Method POST `
  -ContentType "application/json" `
  -Body '{"chat_id":"YOUR_CHAT_ID","text":"Telegram bot test"}'

▶️ Running the script

node extractGrades.js

Expected behavior:

  • launches Chromium through Playwright,
  • logs in to esDnevnik,
  • scrapes graded tasks, upcoming tasks, and recent grades,
  • writes a Markdown report to the configured local output path,
  • sends a Telegram report on school days,
  • updates last_sent.txt to prevent duplicate sends on the same day.

📨 Telegram behavior

The script can send a daily summary including average grade, upcoming tasks, and recent grades. If the message becomes too long, it is automatically split into multiple Telegram messages.

Example Telegram message

Telegram daily report example

🔒 Security and privacy

This project is designed to keep credentials and messaging secrets outside the codebase by using environment variables for authentication and bot configuration.

Do not commit real esDnevnik usernames, passwords, Telegram bot tokens, chat IDs, generated personal reports, or local runtime files to the repository.

Before publishing changes, review staged files carefully and confirm that no personal data, screenshots with sensitive information, or locally generated output has been included unintentionally.

If you use this project with a public repository, treat all student data, school account data, and Telegram bot credentials as sensitive information and store them only in secure local environment settings.

⏰ Scheduling

The Windows Task Scheduler flow used in the project history registers the script to run at logon with a 5-minute delay, then relies on the once-per-day guard in last_sent.txt plus the school-day check inside the script to avoid duplicate or weekend sends.

Create the task

$action = New-ScheduledTaskAction -Execute node -Argument "C:\projects\extractGrades.js" -WorkingDirectory "C:\projects"
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$trigger.Delay = 'PT5M'
$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 5) -StartWhenAvailable
Register-ScheduledTask -TaskName "esDnevnikOnStartup" -Action $action -Trigger $trigger -Settings $settings -Force

Verify the task

Get-ScheduledTask -TaskName "esDnevnikOnStartup" | Select-Object TaskName, State

Run a manual test

Start-ScheduledTask -TaskName "esDnevnikOnStartup"
Get-ScheduledTaskInfo -TaskName "esDnevnikOnStartup" | Select-Object LastRunTime, LastTaskResult, NextRunTime

A LastTaskResult value of 0 indicates a successful run.

📝 Output

The current setup writes a Markdown report to a local workspace.

Typical report content includes:

  • fetched timestamp,
  • upcoming tasks,
  • graded tasks,
  • recent dashboard grades.

About

This project focuses on personal automation around Serbia’s `moj.esdnevnik.rs` portal, with Windows-first scheduling, Markdown reporting, and Telegram delivery.

Topics

Resources

License

Stars

Watchers

Forks

Contributors