scratchattach icon indicating copy to clipboard operation
scratchattach copied to clipboard

implement user.classroom getter function

Open faretek1 opened this issue 9 months ago • 0 comments

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})

Image

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.

faretek1 avatar Apr 13 '25 21:04 faretek1