From 995a621b90f1e5477fbe3c5eb98e6b53f9c95b89 Mon Sep 17 00:00:00 2001 From: Matic Babnik Date: Sat, 13 Dec 2025 17:17:58 +0100 Subject: [PATCH 1/4] fix: Send less requests, improve UA --- src/easistent/fetcher.ts | 4 +++- src/easistent/school.ts | 29 ++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/easistent/fetcher.ts b/src/easistent/fetcher.ts index 1280bad..5e2f279 100644 --- a/src/easistent/fetcher.ts +++ b/src/easistent/fetcher.ts @@ -1,3 +1,5 @@ +import { version } from "../../package.json" with { type: "json" }; + export type TimetableRequestParams = { schoolId?: number; classId?: number; @@ -13,7 +15,7 @@ export class Fetcher { private static readonly fetchOptions: RequestInit = { method: "GET", headers: { - "user-agent": "Mozilla/5.0 (easistent-tt, matic says hi)", + "user-agent": `Mozilla/5.0 (X11; Linux x86_64) EasistentTt/${version} (https://github.com/MaticBabnik/easistent-tt; Merry Christmas)`, "content-type": "application/x-www-form-urlencoded; charset=UTF-8", accept: "text/html", }, diff --git a/src/easistent/school.ts b/src/easistent/school.ts index 8116a0c..c4340f3 100644 --- a/src/easistent/school.ts +++ b/src/easistent/school.ts @@ -49,8 +49,11 @@ export type WeekData = { scrapedAt: number; }; -const DEFAULT_TTL = 30 * 60 * 1000; -const SCRAPE_INTERVAL = DEFAULT_TTL - 30_000; +const HOUR = 1000 * 60 * 60; +const DEFAULT_TTL = 2 * HOUR; +const SCRAPE_INTERVAL = HOUR - 30_000; + +const delay = (ms: number) => new Promise((res) => setTimeout(res, ms)); export class School { public errors: SchoolError[] = []; @@ -370,17 +373,33 @@ export class School { if (this.asRunning) return; this.asRunning = true; - const as = () => { - console.log("Refreshing cache"); + /** + * Scrape surrounding weeks half as often + * starts as false but will get flipped on first run + */ + let scrapeSurrounding = false; + + const as = async () => { const week = this.getWeekForDate(); + scrapeSurrounding = !scrapeSurrounding; + console.log(`Refreshing cache, surrounding=${scrapeSurrounding}`); + + if (!scrapeSurrounding) { + await this.getWeek(week, true); + return; + } + const from = Math.max(1, week - 1); const to = Math.min(52, week + 1); for (let i = from; i <= to; i++) { - this.getWeek(i, true); + // biome-ignore lint/performance/noAwaitInLoops: intentional + await this.getWeek(i, true); + delay(3333); // be nice to the server } }; + setInterval(as, SCRAPE_INTERVAL); as(); } From 0a05b96b76e4534f8b84c326c5443f0446a3f6ba Mon Sep 17 00:00:00 2001 From: Matic Babnik Date: Sat, 13 Dec 2025 17:20:11 +0100 Subject: [PATCH 2/4] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0e5cde9..82148b7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "easistent-tt", "module": "src/index.ts", "type": "module", - "version": "4.4.1-evil-world", + "version": "4.4.2-mrk", "devDependencies": { "bun-types": "latest", "typescript": "^5.8.3", From 1d1e7e3b7b16928560dd5ed9afee166d4c3bf5bc Mon Sep 17 00:00:00 2001 From: Matic Babnik Date: Sat, 13 Dec 2025 17:36:09 +0100 Subject: [PATCH 3/4] feat: CI --- .github/workflows/ci.yaml | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..d1ed64e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,47 @@ +name: CI + +permissions: + contents: read + packages: write + +on: + push: + branches: [main] + tags: ["v*.*.*"] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: docker/login-action@v3.6.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/setup-qemu-action@v3 + + - uses: docker/setup-buildx-action@v3 + + - id: meta + uses: actions/docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/${{github.repository}} + tags: | + type=semver,pattern={{version}} + type=ref,event=branch + type=ref,event=pr + + - name: Build image + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 0eb76d745de2512918fb6cc62a0cf027fd79d657 Mon Sep 17 00:00:00 2001 From: Matic Babnik Date: Sat, 13 Dec 2025 17:40:29 +0100 Subject: [PATCH 4/4] fix: CI --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d1ed64e..53c24b7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,7 +28,7 @@ jobs: - uses: docker/setup-buildx-action@v3 - id: meta - uses: actions/docker/metadata-action@v5 + uses: docker/metadata-action@v5 with: images: | ghcr.io/${{ github.repository_owner }}/${{github.repository}}