Skip to content
This repository has been archived by the owner on Jan 27, 2018. It is now read-only.

Commit

Permalink
Fixed parsing of course name string
Browse files Browse the repository at this point in the history
Accidentially covered tags not belonging to the name, causing a regex
match failure elsewhere.

Closes #20
  • Loading branch information
Fabian Knorr committed Apr 27, 2017
1 parent ae82ed6 commit 1a2382f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions studip/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def parse_semester_list(html):

class CourseListParser(HTMLParser):
State = IntEnum("State", "before_sem before_thead_end table_caption before_tr "
"tr td_group td_img td_id td_name after_td")
"tr td_group td_img td_id td_name after_td a_name")

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -184,6 +184,7 @@ def handle_starttag(self, tag, attrs):
elif self.state == State.td_name and tag == "a":
attrs = dict(attrs)
self.current_id = get_url_field(attrs["href"], "auswahl")
self.state = State.a_name

def handle_endtag(self, tag):
State = CourseListParser.State
Expand All @@ -195,6 +196,9 @@ def handle_endtag(self, tag):
elif self.state == State.table_caption:
if tag == "caption":
self.state = State.before_thead_end
elif self.state == State.a_name:
if tag == "a":
self.state = State.td_name
elif self.state == State.after_td:
if tag == "tr":
full_name = compact(self.current_name)
Expand All @@ -213,7 +217,7 @@ def handle_data(self, data):
State = CourseListParser.State
if self.state == State.td_id:
self.current_number += data
elif self.state == State.td_name:
elif self.state == State.a_name:
self.current_name += data
elif self.state == State.table_caption:
self.current_semester += data
Expand Down

0 comments on commit 1a2382f

Please sign in to comment.