scratchattach icon indicating copy to clipboard operation
scratchattach copied to clipboard

Classroom alerts parser & update Classroom private activity parser. solves #304

Open faretek1 opened this issue 7 months ago • 0 comments

Classroom alerts/activity parser (updates)

This pr reverts commit d93c9a4c25a4f13fcb6692de6ccf1289b9208f11.

the commits reverted in that commit were intended to be the contents of this PR. When cleaning up my workspace in my IDE, it seems that I accidentally linked to https://github.com/TimMcCool/scratchattach/ instead of https://github.com/faretek1/scratchattach/

In #294, many Classroom methods were added, including the ability to fetch classrooms' private activity (using a teacher account's session) and the ability to fetch classroom alerts (using a teacher account's session). This PR improves these features: (`site.classroom.Classroom.activity` & `site.session.Session.classroom_alerts`)

site.classroom.Classroom.activity

The parser for the private classroom activity has been updated to more accurately match the scratch website's HTML, since the 'empty' cases actually just relay onto the case below them.

i found this out when testing the classroom alerts parser which had the same issue, and fixed both issues.

site.session.Session.classroom_alerts

(solves #304) The main feature of this PR is the implementation of the Classroom alert parser. The function for requesting to the scratch api was already implemented in #294, but the site.classroom.Classroom.activity would just return a list of JSON objects, which is not very helpful for the user.

This is done with an edit to enums.py, classroom.py, and a new file alerts.py. Classroom alerts are implemented as the EducatorAlert dataclass,, with 9 attributes. These also have 3 getter methods:

  • alert_type for parsing/looking-up the 'type' attribute using an enum. This enum is used internally in the message getter
  • message for emulating Scratch's own display of the alert, e.g. "Blockly by TimMcCool was censored"
  • target_object_title for getting the title of the linked project/studio (if it's a comment or other stuff, returns None): used by message

appendix

there are still a few more things to do:

  • [ ] docstrings
  • [ ] comments
  • [ ] code review

there are also a few # todo: <...> comments within the code, which cannot be done until certain conditions are met:

  • [ ] test the parser with a studio-related alert (when possible)
  • [ ] implement the regular user's alert (not classroom), and see if the classroom alert could subclass that

faretek1 avatar Apr 13 '25 22:04 faretek1