Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
fix: Add text if empty teacher row
Browse files Browse the repository at this point in the history
  • Loading branch information
0niel committed Aug 30, 2023
1 parent 53facd8 commit bc34669
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rtu_schedule_parser"
version = "2.3.1"
version = "2.3.2"
description = "Easy extraction of the MIREA - Russian Technological University schedule from Excel documents."
authors = ["Sergey Dmitriev <[email protected]>"]

Expand Down
2 changes: 1 addition & 1 deletion rtu_schedule_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.3.1"
__version__ = "2.3.2"
__author__ = "Sergey Dmitriev"

from .excel_parser import ExcelScheduleParser
Expand Down
12 changes: 12 additions & 0 deletions rtu_schedule_parser/excel_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,22 @@ def try_get_room(room) -> Room:

return result

def __replace_empty_teachers_to_text(self, text: str) -> str:
"""Иногда стоят подгруппы бе преподавателей, заменяем их на текст. Такое бывает, если расписание не доделано."""
return re.sub(
r"^(\d п/г)$",
r"Нет,\g<1>",
text.strip(),
flags=re.IGNORECASE | re.MULTILINE,
)


def get_teachers(self, names_cell_value: str) -> list[str] | list[tuple[str, int]]:
if not re.search(r"[а-яА-Я]", names_cell_value):
return []

names_cell_value = self.__replace_empty_teachers_to_text(names_cell_value)

teachers_names = names_cell_value.strip()

re_typos = r"[а-яё]{1}(,) {0,2}[а-яё]{1}[. ]"
Expand Down
9 changes: 6 additions & 3 deletions rtu_schedule_parser/excel_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ def __parse_lessons(
lesson_teachers[0], tuple
):
if len(lesson_teachers) < lessons_len:
if lesson_teachers[0][0] == lesson_teachers[1][0]:
lesson_teachers.insert(0, ("", None))
else:
try:
if lesson_teachers[0][0] == lesson_teachers[1][0]:
lesson_teachers.insert(0, ("", None))
else:
lesson_teachers.append(("", None))
except IndexError:
lesson_teachers.append(("", None))

subgroup = lesson_teachers[i][1]
Expand Down
14 changes: 13 additions & 1 deletion tests/excel_formatter/test_get_teachers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,16 @@ def test_get_teacher_21(excel_formatter):
def test_get_teacher_22(excel_formatter):
result = excel_formatter.get_teachers("1 п/г\n2 п/г")

assert result == []
assert result == [
('Нет', 1),
('Нет', 2),
]


def test_get_teacher_23(excel_formatter):
result = excel_formatter.get_teachers("1 п/г\n\n2 п/г")

assert result == [
('Нет', 1),
('Нет', 2),
]
2 changes: 1 addition & 1 deletion tests/test_rtu_schedule_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "2.3.1"
assert __version__ == "2.3.2"

0 comments on commit bc34669

Please sign in to comment.