Returns the number of open and ended classes owned by a teacher session. If this is not a teacher session, (0, 0) is returned.
(self)
| 905 | raise exceptions.FetchError() |
| 906 | |
| 907 | def mystuff_classes_counts(self) -> tuple[int, int]: |
| 908 | """ |
| 909 | Returns the number of open and ended classes owned by a teacher session. |
| 910 | If this is not a teacher session, (0, 0) is returned. |
| 911 | """ |
| 912 | with requests.no_error_handling(): |
| 913 | resp = requests.get("https://scratch.mit.edu/educators/classes/") |
| 914 | |
| 915 | if resp.status_code == 403: |
| 916 | return 0, 0 # non-teacher account |
| 917 | |
| 918 | soup = BeautifulSoup(resp.text, "html.parser") |
| 919 | sidebar = soup.find("div", {"id": "sidebar", "class": "tabs-index"}) |
| 920 | if not sidebar: |
| 921 | return 0, 0 |
| 922 | |
| 923 | count_elem = sidebar.find("span", {"data-content": "classroom-count"}) |
| 924 | ended_elem = sidebar.find("span", {"data-content": "closed-count"}) |
| 925 | if not count_elem or not ended_elem: |
| 926 | return 0, 0 |
| 927 | |
| 928 | count = str(count_elem.text).strip() |
| 929 | ended_count = str(ended_elem.text).strip() |
| 930 | |
| 931 | return int(count), int(ended_count) |
| 932 | |
| 933 | def mystuff_classes(self, mode: str = "Last created", page: Optional[int] = None) -> list[classroom.Classroom]: |
| 934 | if not self.is_teacher: |