Scraper Client

class routinepy.lib.scraper.client.ScraperClient[source]

Client for fetching routine data through web scraping the BUBT webpage

Extract the links for class, exam, and supplementary exam routines from the university’s webpage

Raises:

ValueError – Failed to get routine webpage

Returns:

A dictionary containing three categories of routine links:

  • class: A dictionary with a links key containing a list of dictionaries,

    each with program_code (str) and link (str) for class routines.

  • exam: A dictionary with a links key containing a list of dictionaries,

    each mapping shift names to program-specific exam routine links.

  • sup_exam: A dictionary with a links key containing a list of supplementary exam routine links.

Return type:

dict

async get_class_routine(program_code: ProgramCode, course_code: str = None, faculty_code: str = None, intake: str = None, section: str = None) list[ClassPeriod] | None[source]

Get class routine data based on provided filters.

Parameters:
  • program_code (ProgramCode) – The program code to filter by (e.g., 006, 001)

  • course_code (str, optional) – The course code to filter by (e.g., CSE 101, CSE 331), defaults to None

  • faculty_code (str, optional) – The faculty member code to filter by (e.g., MDI, MAFI ), defaults to None

  • intake (str, optional) – The intake number to filter by (e.g., 49, 50), defaults to None

  • section (str, optional) – The section number to filter by (e.g., 1, 2), defaults to None

Raises:

ValueError – If invalid or incompatible filter combinations are provided

Returns:

A list of filtered ClassPeriod objects representing the class routine

Return type:

list[ClassPeriod] | None

Note

  • Program codes follow the university’s standard numbering system

  • Filtering by room number is not implemented as we need to download the routines of all programs.

async get_exam_routine(program_code: ProgramCode, course_code: str = None, faculty_code: str = None, intake: str = None, section: str = None) list[TermExam] | None[source]

Get exam routine data based on provided filters.

Parameters:
  • program_code (ProgramCode) – The program code to filter by (e.g., 006, 001)

  • course_code (str, optional) – The course code to filter by (e.g., CSE 101, CSE 331), defaults to None

  • faculty_code (str, optional) – The faculty member code to filter by (e.g., MDI, MAFI ), defaults to None

  • intake (str, optional) – The intake number to filter by (e.g., 49, 50), defaults to None

  • section (str, optional) – The section number to filter by (e.g., 1, 2), defaults to None

Raises:

ValueError – If invalid or incompatible filter combinations are provided

Returns:

A list of filtered TermExam objects representing the exam routine

Return type:

list[TermExam] | None

Note

  • Program codes follow the university’s standard numbering system

  • Filtering by room number is not implemented as it’s not possible yet to extract and parse varities of routine PDFs.

Warning

  • Only ProgramCode.CSE_DAY is currently supported

async get_class_routine_html(program_code: ProgramCode)[source]

Get HTML content for a specific class routine

Parameters:

program_code (ProgramCode) – The program code to filter by (e.g., 006, 001)

Raises:
  • ValueError – no class routine links are found

  • ValueError – the routine cannot be downloaded

  • ValueError – class routine for program not found

Returns:

HTML content of the class routine

Return type:

str

Get exam routine pdf link from the routine webpage

Parameters:

program_code (ProgramCode) – The program code to filter by (e.g., 006, 001)

Raises:
  • ValueError – No exam routine links found from the routine page

  • ValueError – No exam pdf link found for the given program code

Returns:

the exam routine PDF link of the program

Return type:

str

Example

Basic Setup

First, initialize the Scraper client:

from routinepy.lib import ScraperClient

client = ScraperClient()

Some Scenarios

  1. Department Routine - Get class routine for an entire department:

data = await client.get_class_routine(program_code=ProgramCode.CSE_Day)
  1. Faculty Routine - Get class routine for a specific faculty member:

data = await client.get_class_routine(faculty_code="MDI")
  1. Intake Routine - Get class routine for a specific department intake:

data = await client.get_class_routine(program_code=ProgramCode.CSE_Day, intake="50")
  1. Exam Routine - Get exam routine for a specific department intake:

data = await client.get_exam_routine(
   program_code=ProgramCode.CSE_Day,
   intake="50"
)

Warning

  • Only ProgramCode.CSE_DAY is currently supported