rtu-schedule-unofficial-client
v1.0.13
Published
NPM package for scraping RTU schedule data from nodarbibas.rtu.lv
Downloads
1,074
Maintainers
Readme
Installation
npm install rtu-schedule-unofficial-clientQuick Start
import { RTUSchedule } from 'rtu-schedule-unofficial-client';
const rtu = new RTUSchedule();
// Get available periods, programs, courses, groups
const periods = await rtu.getPeriods();
const programs = await rtu.getPrograms('25/26-R');
const courses = await rtu.getCourses('25/26-R', 'RDBD0');
const groups = await rtu.getGroups('25/26-R', 'RDBD0', 1);
// Get schedule
const schedule = await rtu.getSchedule({
period: '25/26-R', // Autumn 2025/2026
program: 'RDBD0', // Computer Systems
course: 1, // 1st year
group: 13 // Group 13 (optional)
});
// Work with results
console.log(schedule.count); // Entry count
const lectures = schedule.filterByType('lecture'); // Only lectures
const thisWeek = schedule.getThisWeek(); // This week's schedule
const byDay = schedule.groupByDate(); // Group by dateAPI Methods
Discovery
// All available semesters
const periods = await rtu.getPeriods();
// → [{ id, name, code, season, startDate, endDate, isSelected }, ...]
// Current semester
const current = await rtu.getCurrentPeriod();
// Programs for a semester (by ID, code, or name)
const programs = await rtu.getPrograms('25/26-R');
const programs = await rtu.getPrograms(45);
const programs = await rtu.getPrograms('Autumn 2025');
// Courses and groups
const courses = await rtu.getCourses('25/26-R', 'RDBD0');
const groups = await rtu.getGroups('25/26-R', 'RDBD0', 1);Getting Schedule
const schedule = await rtu.getSchedule({
// Period - code, name, or ID
period: '25/26-R', // or: 'Autumn 2025', periodId: 45
// Program - code, name, or ID
program: 'RDBD0', // or: 'Computer Systems', programId: 123
// Course (required)
course: 1,
// Group (optional - without it returns all groups)
group: 13,
// Date range (optional - defaults to semester dates)
startDate: '2025-09-01',
endDate: '2025-12-31'
});Schedule Class
Filtering
All filters return a new Schedule object:
schedule.filter(e => e.durationMinutes > 60) // Custom filter
schedule.filterByType('lecture') // By type
schedule.filterByType(['lecture', 'lab']) // Multiple types
schedule.filterByDateRange(from, to) // Date range
schedule.filterByDate(date) // Specific date
schedule.filterByLecturer('Smith') // By lecturer
schedule.filterBySubject('Programming') // By subject
schedule.filterByLocation('Building A') // By location
schedule.filterByDayOfWeek(1) // By weekday (1=Monday)Types: lecture | practical | lab | seminar | consultation | exam | test | other
Grouping
schedule.groupByWeek() // Map<weekNumber, ScheduleEntry[]>
schedule.groupByDate() // Map<'YYYY-MM-DD', ScheduleEntry[]>
schedule.groupByDayOfWeek() // Map<1-7, ScheduleEntry[]>
schedule.groupBySubject() // Map<subjectCode, ScheduleEntry[]>
schedule.groupByLecturer() // Map<name, ScheduleEntry[]>
schedule.groupByType() // Map<type, ScheduleEntry[]>Convenience Methods
schedule.getToday() // Today's entries
schedule.getTomorrow() // Tomorrow's entries
schedule.getThisWeek() // This week's entries
schedule.getNextWeek() // Next week's entries
schedule.getUpcoming(7) // Next N days
schedule.getWeek(36) // Specific weekAggregation
schedule.getLecturers() // string[] - unique lecturers
schedule.getSubjects() // {name, code}[] - unique subjects
schedule.getLocations() // string[] - unique locations
schedule.getTypes() // ScheduleEntryType[] - used types
schedule.getDateRange() // {start, end} | null - date rangeProperties
schedule.count // Entry count
schedule.isEmpty // Is empty
schedule.first // First entry
schedule.last // Last entry
schedule.entries // ScheduleEntry[] - all entries
schedule.sorted('asc') // Sorted by date
schedule.toArray() // Array copy
// Iterable
for (const entry of schedule) { ... }
[...schedule]ScheduleEntry Structure
interface ScheduleEntry {
id: number;
subject: { name: string; code: string };
// Time
date: Date;
startTime: string; // "09:00"
endTime: string; // "10:30"
startDateTime: Date;
endDateTime: Date;
durationMinutes: number;
// Location
location: string; // "Building A-423"
building?: string; // "Building A"
room?: string; // "423"
// People
lecturer: string;
lecturers: string[]; // If multiple
// Classification
type: ScheduleEntryType;
typeRaw: string; // Original type string
// Group
group: string;
groups: string[]; // If multiple
// Week
weekNumber: number;
dayOfWeek: number; // 1-7 (Mon-Sun)
dayName: string; // "Monday"
}Error Handling
import {
PeriodNotFoundError, // Period not found
ProgramNotFoundError, // Program not found
CourseNotFoundError, // Course not found
GroupNotFoundError, // Group not found
InvalidOptionsError, // Invalid options
DiscoveryError // Discovery error
} from 'rtu-schedule-unofficial-client';
try {
const schedule = await rtu.getSchedule({ ... });
} catch (error) {
if (error instanceof PeriodNotFoundError) {
console.error(`Period not found: ${error.input}`);
}
}Configuration
const rtu = new RTUSchedule({
timeout: 10000, // API timeout ms
cacheTimeout: 300000, // API cache 5 min
discoveryCacheTimeout: 3600000 // Discovery cache 1h
});
// Cache
rtu.clearCache(); // Clear cache
await rtu.refresh(); // RefreshLow-Level API
import { apiClient, htmlParser } from 'rtu-schedule-unofficial-client';
// Direct API calls
const events = await apiClient.fetchSemesterProgramEvents({
semesterProgramId: 123, year: 2025, month: 9
});
const subjects = await apiClient.fetchSemesterProgramSubjects(123);
const isPublished = await apiClient.checkSemesterProgramPublished(123);
const groups = await apiClient.findGroupsByCourse({
courseId: 1, semesterId: 45, programId: 123
});
const courses = await apiClient.findCoursesByProgram({
semesterId: 45, programId: 123
});
// HTML parsing
const semesters = htmlParser.parseHtmlSemesters(html);
const programs = htmlParser.parseHtmlPrograms(html);TypeScript Support
import type {
// High-level
StudyPeriod, StudyProgram, StudyCourse, StudyGroup,
ScheduleEntry, ScheduleEntryType, GetScheduleOptions,
// Low-level
SemesterEvent, Subject, Group, Course, Faculty, Semester
} from 'rtu-schedule-unofficial-client';Examples
Full Workflow
import { RTUSchedule } from 'rtu-schedule-unofficial-client';
async function getMySchedule() {
const rtu = new RTUSchedule();
// 1. Get available periods for UI dropdown
const periods = await rtu.getPeriods();
console.log('Periods:', periods.map(p => p.name));
// 2. Get programs for selected period
const programs = await rtu.getPrograms(periods[0].id);
console.log('Programs:', programs.map(p => `${p.name} (${p.code})`));
// 3. Get schedule
const schedule = await rtu.getSchedule({
period: '25/26-R',
program: 'RDBD0',
course: 1,
group: 13
});
// 4. Analyze schedule
console.log(`Total: ${schedule.count} entries`);
console.log(`Lecturers: ${schedule.getLecturers().join(', ')}`);
console.log(`Subjects: ${schedule.getSubjects().map(s => s.name).join(', ')}`);
// 5. Filter and group
const lectures = schedule.filterByType('lecture');
const byWeek = schedule.groupByWeek();
for (const [week, entries] of byWeek) {
console.log(`Week ${week}: ${entries.length} entries`);
}
return schedule;
}