Agentic Browser

AI agent for web automation and scraping, designed to plan, execute, and verify actions across any website

Academic portal integration

Introduction#

JIIT portal via pyjiit: sessions, attendance, exams, subjects, grades, and the FastAPI wrappers around them.

Project structure#

The integration spans a FastAPI application with dedicated router and service layers for pyjiit, backed by a set of pyjiit utilities that encapsulate portal communication, encryption, and data models.

Core components#

  • PyJIIT Router: Exposes endpoints for login, semesters, and attendance. It validates requests and delegates to the service layer.
  • PyJIIT Service: Orchestrates session creation, data retrieval, and response shaping. It handles session deserialization and hard-coded semester selection for attendance.
  • Webportal and WebportalSession: Encapsulate portal authentication, token decoding, and HTTP interactions with the JIIT API.
  • Data Models: Attendance, ExamEvent, Registrations, and Semester types define structured academic data.
  • Encryption and Utilities: Payload serialization/deserialization, LocalName header generation, and date-based keys enable secure communication.
  • Exceptions: Distinct exception types model API errors, login failures, session invalidation, and account-related issues.

Architecture overview#

Stack from the outside in:

  • API Layer: FastAPI app registers routers and exposes endpoints under a unified prefix.
  • Router Layer: Validates requests and invokes the service layer.
  • Service Layer: Manages sessions and orchestrates academic data workflows.
  • Tool Layer: Implements portal-specific logic, encryption, and data models.

Detailed component analysis#

Authentication and session management#

  • Login flow:
  • Router accepts BasicAuthRequest credentials.
  • Service constructs a Webportal instance and calls student_login with a default captcha.
  • Webportal performs two-step token exchange and returns a WebportalSession containing token, expiry, and metadata.
  • Session decoding:
  • WebportalSession parses the token to compute expiry and prepares Authorization headers.
  • Session validation:
  • The authenticated decorator checks session presence and optionally expiry (currently commented out due to API behavior).

Attendance tracking#

  • Workflow:
  • Service accepts a session payload (raw or nested) and builds a WebportalSession.
  • Retrieves attendance meta to obtain headers and semesters.
  • Uses a hardcoded registration mapping to resolve registration_id for a target registration_code.
  • Builds a Semester object and fetches attendance for the latest header.
  • Processes raw attendance items to normalize subject names and extract codes.
  • Output:
  • Returns a list of attendance records with normalized subject names and extracted codes.

Exam schedule retrieval#

  • Workflow:
  • Retrieve semesters with exam events for the student.
  • Select an exam event and fetch the schedule for that event.
  • Output:
  • Returns schedule data for the chosen exam event.

Course registration assistance#

  • Workflow:
  • Retrieve registered semesters for the student.
  • Fetch registered subjects and faculty details for a given semester.
  • Output:
  • Returns total credits and a list of RegisteredSubject entries.

Token management capabilities#

  • Captcha handling:
  • Default captcha is provided for initial login attempts.
  • Captcha instances carry captcha, hidden, and image fields and can produce a payload.
  • Token decoding:
  • WebportalSession decodes the token’s payload to compute expiry.
  • LocalName header:
  • Encryption utilities generate a LocalName header required for every request.

Academic data processing workflows#

  • Attendance normalization:
  • Extract codes from subject names using regex and strip bracketed suffixes.
  • Grade and Transcript:
  • Retrieve semesters for grade card, fetch program and branch IDs, and obtain grade card data.
  • Download marks PDF for a semester.
  • SGPA/CGPA:
  • Fetch cumulative and semester-wise SGPA/CGPA data.

Request/Response handling for academic operations#

  • Login:
  • Request: BasicAuthRequest with username and password.
  • Response: Session payload compatible with WebportalSession.
  • Semesters:
  • Request: Session payload (full or raw).
  • Response: List of registration_id and registration_code pairs.
  • Attendance:
  • Request: Session payload and optional registration_code.
  • Response: Normalized attendance records.

Dependency analysis#

  • Router depends on PyJIIT Service for business logic.
  • Service depends on Webportal and WebportalSession for session management and API interactions.
  • Webportal depends on Encryption utilities for payload handling and on Exceptions for error modeling.
  • Data models (Attendance, ExamEvent, Registrations, Semester) are used across workflows.

Performance considerations#

  • Payload encryption/decryption overhead: Serialization and AES operations occur per request; minimize unnecessary re-encryptions by caching session tokens and reusing headers.
  • Network latency: Batch related operations (e.g., semesters, registrations, attendance) within a single session to reduce repeated authentication overhead.
  • Regex normalization: Keep normalization logic efficient; avoid repeated computations by precomputing patterns.
  • Token expiry handling: While automatic expiry checks are currently disabled due to API behavior, monitor for future reliability improvements.

Troubleshooting guide#

  • Authentication failures:
  • Verify username/password and captcha correctness. The default captcha is provided for convenience but may require dynamic retrieval in production.
  • Inspect LoginError exceptions raised during token exchange.
  • Session timeouts/expiry:
  • WebportalSession decodes token expiry; handle SessionExpired errors when encountered.
  • Re-authenticate using the login endpoint to refresh the session.
  • Data synchronization problems:
  • Confirm that the session payload is passed correctly (either full response or raw response dict).
  • For attendance, ensure the hardcoded registration mapping aligns with the intended semester.
  • Portal downtime:
  • Monitor HTTP 401 responses and APIError exceptions; retry after the portal stabilizes.
  • Subject normalization issues:
  • Review regex patterns used to extract codes from subject names and adjust if naming conventions change.

Conclusion#

Session-aware wrappers and typed models keep portal quirks contained. Watch session lifetime; the portal will invalidate you without a polite error.

Appendices#

API endpoints overview#

  • POST /api/pyjiit/login
  • Request: BasicAuthRequest
  • Response: Session payload compatible with WebportalSession
  • POST /api/pyjiit/semesters
  • Request: Session payload (full or raw)
  • Response: List of registration_id and registration_code pairs
  • POST /api/pyjiit/attendence
  • Request: AttendanceReq (session_payload, optional registration_code)
  • Response: Normalized attendance records