mirror of
https://github.com/Code-For-Groningen/temmies.git
synced 2025-03-15 07:10:15 +01:00
30 lines
999 B
Python
30 lines
999 B
Python
# Module to handle each assignment (most difficult part)
|
|
|
|
from Base import Base
|
|
from Exercise import Exercise
|
|
from requests import Session
|
|
|
|
|
|
class Assignment(Base):
|
|
def __init__(self, url:str, name:str, session:Session, parent):
|
|
super().__init__(url, name, session, parent)
|
|
self.download = Downloadable(name, session, self)
|
|
|
|
def __str__(self):
|
|
return f"Assignment {self.name} in course {self.parent.name}"
|
|
|
|
def getExercises(self) -> list[Exercise]:
|
|
# Find li large
|
|
ul = self.soup.find('ul', class_='round')
|
|
|
|
# Turn each li to an exercise instance
|
|
return self.liLargeToExercises(ul, self.session, self)
|
|
|
|
def getExercise(self, name:str) -> Exercise:
|
|
# Get the exercise
|
|
r = self.session.get(self.url)
|
|
soup = BeautifulSoup(r.text, 'lxml')
|
|
# Search by name
|
|
exercise = soup.find('a', text=name)
|
|
# Get the url and transform it into an exercise object
|
|
return Exercise(url=exercise['href'], name=name, session=self.session, assignment=self) |