chuvsu-js 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,13 +133,12 @@ function parseSessionSchedule(doc, educationType) {
133
133
  const cellHtml = dateCell.innerHTML ?? "";
134
134
  const brMatch = cellHtml.match(/<br\s*\/?>\s*(.+)/i);
135
135
  const weekday = brMatch ? brMatch[1].trim() : "";
136
- // Data cell is the next td.trdata sibling in the same row
137
- const row = dateCell.parentElement;
138
- if (!row)
139
- continue;
140
- const dataCell = row.querySelector("td.trdata:not(.trfd)");
141
- if (!dataCell)
136
+ // Live session tables repeat the date cell after the data cell. Only the
137
+ // leading date cell has the schedule data as its next sibling.
138
+ const dataCell = dateCell.nextElementSibling;
139
+ if (!dataCell?.matches("td.trdata:not(.trfd)")) {
142
140
  continue;
141
+ }
143
142
  const slots = [];
144
143
  for (const entryRow of dataCell.querySelectorAll("table tr")) {
145
144
  const td = entryRow.querySelector("td") ?? entryRow;
@@ -31,13 +31,15 @@ export function parseTransferDiv(div) {
31
31
  const cleaned = part.trim();
32
32
  if (!cleaned)
33
33
  continue;
34
+ const isLessonMeta = cleaned.includes(subject) ||
35
+ (roomMatch?.[1] != null && cleaned.includes(roomMatch[1])) ||
36
+ LESSON_TYPE_RE_I.test(cleaned);
37
+ if (isLessonMeta)
38
+ continue;
34
39
  if (GROUP_CODE_RE.test(cleaned)) {
35
40
  groupsPart = cleaned;
36
41
  continue;
37
42
  }
38
- const isLessonMeta = cleaned.includes(subject) ||
39
- (roomMatch?.[1] != null && cleaned.includes(roomMatch[1])) ||
40
- LESSON_TYPE_RE_I.test(cleaned);
41
43
  if (!isLessonMeta && !teacherPart) {
42
44
  teacherPart = cleaned;
43
45
  }
@@ -3,7 +3,7 @@ import { getLessonNumber } from "../utils/index.js";
3
3
  import { parseSemesterScheduleWith } from "./full-schedule.js";
4
4
  import { parseGroupsString } from "./groups.js";
5
5
  import { parseSubstituteForDiv, parseSubstitutionDiv, parseTransferDiv, } from "./overlays.js";
6
- import { FLEXIBLE_LESSON_TYPE_PATTERN, FLEXIBLE_LESSON_TYPE_RE_I, LESSON_TYPE_RE, SUBGROUP_RE, WEEKS_RE, } from "./patterns.js";
6
+ import { FLEXIBLE_LESSON_TYPE_RE_I, LESSON_TYPE_RE, SUBGROUP_RE, WEEKS_RE, } from "./patterns.js";
7
7
  const DISTANCE_RE = /дистанционно|ДОТ/i;
8
8
  export function parseTeacherFullSchedule(html, educationType) {
9
9
  const doc = parseHtml(html);
@@ -88,12 +88,10 @@ function parseTeacherSessionSchedule(doc, educationType) {
88
88
  const cellHtml = dateCell.innerHTML ?? "";
89
89
  const brMatch = cellHtml.match(/<br\s*\/?>\s*(.+)/i);
90
90
  const weekday = brMatch ? brMatch[1].trim() : "";
91
- const row = dateCell.parentElement;
92
- if (!row)
93
- continue;
94
- const dataCell = row.querySelector("td.trdata:not(.trfd)");
95
- if (!dataCell)
91
+ const dataCell = dateCell.nextElementSibling;
92
+ if (!dataCell?.matches("td.trdata:not(.trfd)")) {
96
93
  continue;
94
+ }
97
95
  const slots = [];
98
96
  for (const entryRow of dataCell.querySelectorAll("table tr")) {
99
97
  const td = entryRow.querySelector("td") ?? entryRow;
@@ -128,11 +126,15 @@ function parseTeacherSessionEntry(td) {
128
126
  const typeMatch = plainText.match(FLEXIBLE_LESSON_TYPE_RE_I);
129
127
  const type = typeMatch ? typeMatch[1].replace(/\.$/, "").toLowerCase() : "";
130
128
  const subgroupMatch = plainText.match(SUBGROUP_RE);
131
- // Groups: text between </span> type and <br>time
132
- const groupsMatch = fullHtml.match(new RegExp(`\\((?:${FLEXIBLE_LESSON_TYPE_PATTERN})\\)\\s*([^<]+?)\\s*<br`, "i"));
133
129
  const timeMatch = fullHtml.match(/<br\s*\/?>\s*(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/);
134
130
  if (!timeMatch)
135
131
  return null;
132
+ const parts = fullHtml
133
+ .split(/<br\s*\/?>/i)
134
+ .map((part) => part.replace(/<[^>]*>/g, "").trim())
135
+ .filter((part) => part.length > 0);
136
+ const groupsPart = parts.find((part) => !part.includes(subject) &&
137
+ !/^\d{2}:\d{2}\s*-\s*\d{2}:\d{2}$/.test(part)) ?? "";
136
138
  return {
137
139
  entry: {
138
140
  room,
@@ -140,7 +142,7 @@ function parseTeacherSessionEntry(td) {
140
142
  type,
141
143
  weeks: { from: 0, to: 0 },
142
144
  teacher: { name: "" },
143
- groups: parseGroupsString(groupsMatch?.[1]),
145
+ groups: parseGroupsString(groupsPart),
144
146
  subgroup: subgroupMatch ? parseInt(subgroupMatch[1]) : undefined,
145
147
  isDistance: DISTANCE_RE.test(plainText) || DISTANCE_RE.test(room),
146
148
  possibleChanges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chuvsu-js",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Node.js library for ChuvSU student portal (lk.chuvsu.ru) and schedule (tt.chuvsu.ru)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",