scratchattach
scratchattach copied to clipboard
implement user.classroom getter function
Implement a method/attribute in the site.user.User class
class User:
# <...>
def classroom(self) -> classroom.Classroom | None:
... # If this is a student user, return a classroom object. If not, return None
The regular api (api.scratch.mit.edu/users/{username}) does not provide classroom information, so this would require webscraping of the user's profile page (scratch.mit.edu/users/{username})
Look for a href that follows this regular expression: \/classes\/\d*\/. if it exists within this <p class="profile-details"> tag, then the user is a student. Otherwise, they are not.