Skip to content

Commit e6acf72

Browse files
committed
fix: parse schedule for courses without IDs by keying on course name
1 parent 040898d commit e6acf72

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/services/course_service.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class CourseService {
335335
if (day != null) colToDayMap[i] = day;
336336
}
337337

338-
// Build schedule map keyed by course ID from the grid
338+
// Build schedule map keyed by course name from the grid
339339
final periodRegex = RegExp(r'第 (\S) 節');
340340
final scheduleMap =
341341
<
@@ -359,18 +359,20 @@ class CourseService {
359359
if (day == null) continue;
360360

361361
final anchors = cells[colIndex].querySelectorAll('a');
362-
if (anchors.isEmpty) continue;
363362

364-
final courseRef = _parseAnchorRef(anchors[0]);
365-
final courseId = courseRef.id;
366-
if (courseId == null) continue;
363+
// Key by course name — works for both regular courses (with <a>
364+
// links) and special entries like 班週會 (plain text).
365+
final courseName = anchors.isNotEmpty
366+
? anchors[0].text.trim()
367+
: cells[colIndex].text.trim();
368+
if (courseName.isEmpty) continue;
367369

368370
final classroomRef = anchors.length >= 3
369371
? _parseAnchorRef(anchors[2])
370372
: null;
371373

372-
scheduleMap.putIfAbsent(courseId, () => []);
373-
scheduleMap[courseId]!.add((
374+
scheduleMap.putIfAbsent(courseName, () => []);
375+
scheduleMap[courseName]!.add((
374376
day: day,
375377
period: period,
376378
classroom: classroomRef,
@@ -398,8 +400,8 @@ class CourseService {
398400
final teacher = _parseCellRef(cells[6]); // TODO: Handle multiple teachers
399401
final classes = _parseCellRefs(cells[7]);
400402

401-
// Look up schedule+classroom from the timetable grid by course ID
402-
final schedule = course.id != null ? scheduleMap[course.id!] : null;
403+
// Look up schedule+classroom from the timetable grid by course name
404+
final schedule = scheduleMap[course.name];
403405

404406
final status = _parseCellText(cells[16]);
405407
final language = _parseCellText(cells[17]);

0 commit comments

Comments
 (0)