Skip to content

Commit

Permalink
Merge pull request #118 from unb-mds/fix/api/web-scraping
Browse files Browse the repository at this point in the history
fix(utils): funções get start e end index com return incorreto
  • Loading branch information
mateusvrs authored Nov 28, 2023
2 parents c59a8ea + 3b7743a commit a0e4b99
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions api/utils/web_scraping.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ def __init__(self, department: str, year: str, period: str, url=URL, session=Non
"javax.faces.ViewState": "j_id1"
}

if session is None: # pragma: no cover
if session is None: # pragma: no cover
self.session = create_request_session() # Create a request session
else:
self.session = session

if cookie is None: # pragma: no cover
if cookie is None: # pragma: no cover
self.cookie = get_session_cookie(self.session)
else:
self.cookie = cookie
Expand Down Expand Up @@ -108,7 +108,7 @@ def get_teachers(self, data: list) -> list:

teachers.append(content[0].strip())

if len(teachers) == 0: # pragma: no cover
if len(teachers) == 0: # pragma: no cover
teachers.append("A definir")

return teachers
Expand All @@ -135,24 +135,26 @@ def check_start(self, *args, **kwargs) -> bool:
return start_index is None and value_start_check and already_included

def check_end(self, *args, **kwargs) -> bool:
end_index = kwargs.get("end_index")

start_interval = kwargs.get("interval")[0]
value_start_check = kwargs.get("value").start() < start_interval

return end_index is None and value_start_check
return value_start_check

def get_start_index(self, intervals, last_included, value) -> Optional[int]:
start_index = None

for index, interval in enumerate(intervals):
if self.check_start(start_index=index, last_included=last_included, interval=interval, index=index, value=value):
return index + 1
return None
if self.check_start(start_index=start_index, last_included=last_included, interval=interval, index=index, value=value):
start_index = index + 1

return start_index

def get_end_index(self, intervals, value) -> int:
for index, interval in enumerate(intervals):
if self.check_end(end_index=index, interval=interval, index=index, value=value):
if self.check_end(interval=interval, index=index, value=value):
return index
return len(intervals)
else:
return len(intervals)

def get_start_and_end(self, value: Iterator, intervals: list[tuple[int, int]], last_included: int) -> tuple[int, int]:
start_index = self.get_start_index(intervals, last_included, value)
Expand Down

0 comments on commit a0e4b99

Please sign in to comment.