I started my master's a couple of months late, which meant catching up on everything at once: deadlines in five courses, announcements I'd missed, and a timetable I didn't know yet. And every time I wanted to check any of it, I had to go through this:
- Open Moodle
- Get redirected to the university sign-in page
- Password
- Find my phone
- Authenticator code
- Dashboard → My courses → click the course → scroll… scroll…
- Where is the deadline??
So I did what any reasonable person does to avoid a 30-second chore: I spent a day automating it.
The result is moodle-watch, a small Python bot that runs free on GitHub Actions and posts this to my Slack:
- 🔔 Alerts: new announcements and forum posts, grades released, new lecture files, due dates that moved, deadlines under 48 h that are still open
- ☀️ A morning digest: today's classes, overdue work, everything due this week
- ⏰ A reminder 30 minutes before each class
- 🔑 A heads-up before my Moodle token expires, and a ⚠️ when Moodle itself is down
Here are the interesting bits, including the parts I got wrong first.
The first idea was the bad one: automate the authenticator
My first thought was "keep the login session alive on a server, or generate the authenticator code automatically". Both are bad ideas:
- Keeping a browser session alive means babysitting a Moodle cookie and a single sign-on (SAML) cookie, both of which expire. Renewing them means a full sign-in again.
- Generating authenticator codes on a server means putting your TOTP secret on that server. That quietly turns two-factor authentication into one factor, run by a script, around a control your university's IT owns. If your MFA is push-based, there's no secret to grab anyway.
The actual answer was hiding in plain sight: the official Moodle mobile app.
How the Moodle app logs in (and how you can too)
The Moodle app signs in once through your normal university sign-in in a browser, MFA included, and gets back a long-lived web-service token. Every request after that is a plain REST call with that token. There's no MFA and no cookies, and by default it lasts about 12 weeks.
First check that your Moodle allows it. This public endpoint needs no login:
curl -s "https://moodle.example.edu/lib/ajax/service-nologin.php" \ -H "Content-Type: application/json" \ --data '[{"index":0,"methodname":"tool_mobile_get_public_config","args":{}}]' Look for "enablemobilewebservice": 1. Then the app opens:
https://moodle.example.edu/admin/tool/mobile/launch.php?service=moodle_mobile_app&passport=<random>&urlscheme=moodlemobile You sign in as usual, and Moodle redirects the browser to moodlemobile://token=<base64>. Your browser can't open that link, but DevTools shows it in the location response header. The base64 decodes to:
md5(site_url + passport) ::: TOKEN [::: privatetoken] That first part is a signature, so the helper script checks it to make sure the token came from the link it just generated:
parts = base64.b64decode(raw).decode().split(":::") if parts[0] != hashlib.md5((site + passport).encode()).hexdigest(): raise SystemExit("Signature mismatch: run the script again and use the new link.") token = parts[1] get_token.py wraps all of this. It checks your Moodle is compatible, prints the link, takes the pasted value at a hidden prompt, tests the token, and stores it straight into your repo's GitHub secrets with gh secret set, so it never appears on screen. You do the authenticator step once a term, in your own browser.
The watcher: read-only by construction
That token can act as you: submit work, post in forums, send messages. So the watcher refuses to call anything that isn't on a read-only allowlist:
READ_ONLY_FUNCTIONS = { "core_webservice_get_site_info", "core_calendar_get_action_events_by_timesort", "mod_assign_get_assignments", "mod_forum_get_forum_discussions", "gradereport_user_get_grade_items", "core_calendar_get_calendar_events", # ... } def call(self, fn, **params): if fn not in READ_ONLY_FUNCTIONS: raise ValueError(f"{fn} is not on the read-only allowlist") Every 30 minutes, a GitHub Actions cron job reads deadlines, assignments, forums, notifications, grades, course contents and calendar events. It compares them with the previous run's state and posts only what changed. The first run just records what already exists, so you don't get a flood of old items.
Classes turned out to be in Moodle too: my lecturer uses the Attendance plugin, and every session is a calendar event with a start time and duration. Those become the morning class list and the 30-minute reminders.
Problem: GitHub cron is late
GitHub's scheduler routinely starts jobs 5–15 minutes late, which is fine for "new grade" but useless for "class in 30 minutes". Two fixes:
- Webhook mode: if a run finds a reminder due within the next 40 minutes, it waits for the exact moment and then posts. It's simple and works with Slack, Discord and Mattermost, but it costs Actions minutes.
- Slack bot mode: with a bot token, the watcher books each reminder in advance with Slack's
chat.scheduleMessage, so Slack delivers it on the minute. If a class moves, its booking key changes, so the old booking gets cancelled and a new one is made. If booking fails, it falls back to waiting.
Making it safe to fork
I wanted classmates to fork it with one click. But forks are public, and so are their GitHub Actions logs. That changed the design:
- Logs show counts only:
ok: 2 alert(s), 1 class(es) in view, 0 booked…. No course names, titles or grades. When a section fails, the log names the section, and the details go to your chat. - The state file holds only ids, timestamps and hashes.
- A test enforces both. It starts a mock Moodle and a mock webhook on localhost, runs
watcher.pyexactly as CI does, and fails if any fixture course name, title, grade or user name appears in stdout, stderr or the state file. I checked that it catches a plantedprint(title).
Then I found a subtler leak. Pull-request workflows from forks can read the default branch's Actions cache, which is where the state lives. And the state held SHA-256 hashes of grades. A grade like 8,00 has maybe a few hundred possible values, so you can reverse its hash by trying them all in under a second.
The fix is to key the hash with a secret that pull requests never get:
HASH_KEY = hashlib.sha256(b"moodle-watcher-state:" + token.encode()).digest() def h(value): return hmac.new(HASH_KEY, str(value).encode(), hashlib.sha256).hexdigest()[:16] When the token is renewed the key changes, so the watcher quietly re-baselines grades instead of reporting every grade as "changed". It still alerts for grade items it has never seen. On top of that, the repo requires approval before any outside contributor's pull request runs workflows.
Problem: public repos fall asleep
GitHub disables scheduled workflows in public repos after 60 days without activity. A fork that just quietly runs would go silent around week nine. The usual fix is a bot that makes empty commits, but that makes forks drift from upstream, so every "Sync fork" turns into a merge.
Instead, the job re-enables its own workflow through the API once a day:
- name: Keep the schedule alive if: always() && github.event_name == 'schedule' continue-on-error: true env: GH_TOKEN: ${{ github.token }} run: | if [ "$(date -u +%H)" = "06" ]; then gh api --method PUT "repos/${GITHUB_REPOSITORY}/actions/workflows/watch.yml/enable" fi Knowing when it's broken
A bot that fails silently is worse than no bot. So:
- Moodle down: network errors, timeouts, HTTP 5xx and HTML maintenance pages (which used to crash the JSON parser) all become short, log-safe reasons. After two failed runs in a row you get "⚠️ Can't reach Moodle since 14:30 (HTTP 503)", repeated every 6 hours. Once it's back you get "✅ reachable again (down ~3 h)". A one-off blip stays quiet.
- Maintenance: the public config endpoint from earlier also reports
maintenanceenabled. The watcher then says "🛠️ Moodle is in maintenance" and includes the university's own maintenance note. - Token expiry: Moodle doesn't tell apps when a token expires, so
get_token.pyrecords the issue date and the watcher warns 5 days before issue date + 84 days. You can pass the real date if you know it. - Chat is broken: if posting to Slack fails, the run exits non-zero, so GitHub emails you. That's the only channel left.
Stack and numbers
- Python standard library only. No
pip install, nothing to keep updated. - About 36 runs a day, roughly 1,100 Actions minutes a month. Free on public forks; private repos get 2,000.
- 28 tests covering diffing, reminders, Slack booking, timeouts, 503s, maintenance pages, recovery, token expiry and the log-leak guard.
Try it
- Fork kings1ay3r/moodle-watch and enable workflows in the Actions tab.
- Follow docs/SETUP.md. It takes about 20 minutes and needs no coding.
- Want it fully private? Use "Use this template → Private" instead.
It defaults to my university's Moodle, but --url points it at yours, and the setup script tells you right away if your Moodle has the mobile app turned off. Check your university's IT rules if you're unsure. It uses the same API and token as the official Moodle app.
Issues and pull requests are welcome, especially from people whose Moodle is set up differently from mine.
Built with Claude Code as my AI pair programmer. I steered the design and tested it against my own Moodle.
