Skip to content
Snippets Groups Projects
Verified Commit 595a5df8 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix reg ex for parsing Untis first level data structure

parent c7397cb3
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,11 @@ and this project adheres to `Semantic Versioning`_. ...@@ -9,6 +9,11 @@ and this project adheres to `Semantic Versioning`_.
Unreleased Unreleased
---------- ----------
Fixed
~~~~~
* Import failed sometimes if there were lessons with names.
`2.3`_ - 2022-06-25 `2.3`_ - 2022-06-25
------------------- -------------------
......
...@@ -9,6 +9,8 @@ test_lesson_element = """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissensc ...@@ -9,6 +9,8 @@ test_lesson_element = """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissensc
test_lesson_element_partial = """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissenschaften, Fokus Physik"~"Nawi"~~n~~;11;12;13;14;15;16;17;""" test_lesson_element_partial = """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissenschaften, Fokus Physik"~"Nawi"~~n~~;11;12;13;14;15;16;17;"""
test_lesson_element_partial_partial = ";11;12;13;14;15;16;17;" test_lesson_element_partial_partial = ";11;12;13;14;15;16;17;"
test_lesson_element_second = """46~0~92~45;~45;~12~11~0~~B~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~21700,45~0~92~45;~45;~0~0~19000~~~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~0"""
def test_untis_split_first(): def test_untis_split_first():
assert untis_split_first("") == [] assert untis_split_first("") == []
...@@ -20,8 +22,14 @@ def test_untis_split_first(): ...@@ -20,8 +22,14 @@ def test_untis_split_first():
assert len(untis_split_first(test_lesson_element)) == 2 assert len(untis_split_first(test_lesson_element)) == 2
assert untis_split_first(test_lesson_element) == [ assert untis_split_first(test_lesson_element) == [
"~~n~~;11;12;13;14;15;16;17;", """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissenschaften, Fokus Physik"~"Nawi"~~n~~;11;12;13;14;15;16;17;""",
"~~n~~;11;12;13;14;15;16;17;", """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissenschaften, Fokus Physik"~"Nawi"~~n~~;11;12;13;14;15;16;17;""",
]
assert len(untis_split_first(test_lesson_element_second)) == 2
assert untis_split_first(test_lesson_element_second) == [
"""46~0~92~45;~45;~12~11~0~~B~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~21700""",
"""45~0~92~45;~45;~0~0~19000~~~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~0""",
] ]
......
...@@ -112,7 +112,7 @@ def untis_split_first( ...@@ -112,7 +112,7 @@ def untis_split_first(
s: str, conv: Callable[[Any], Any] = lambda el: el, remove_empty: bool = True s: str, conv: Callable[[Any], Any] = lambda el: el, remove_empty: bool = True
) -> Sequence: ) -> Sequence:
return clean_array( return clean_array(
re.findall(r"(\"[^\"]+\"|[^,\"]+)*,?", s)[:-1], conv=conv, remove_empty=remove_empty re.findall(r"((?:\"[^\"]+\"|[^,\"]+)*),?", s)[:-1], conv=conv, remove_empty=remove_empty
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment