Skip to content

Commit 444fac2

Browse files
committed
ci: teacher auth
1 parent 5aff97b commit 444fac2

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

scratchattach/site/classroom.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ def update(self):
9191
if pfx in script.text:
9292
educator_username = commons.webscrape_count(script.text, pfx, sfx, str)
9393

94-
ret = {"id": self.id,
95-
"title": title,
96-
"description": description,
97-
"status": status,
98-
"educator": {"username": educator_username},
99-
"is_closed": True
100-
}
94+
ret: typed_dicts.ClassroomDict = {
95+
"id": self.id,
96+
"title": title,
97+
"description": description,
98+
"educator": {},
99+
"status": status,
100+
"is_closed": True
101+
}
102+
103+
if educator_username:
104+
ret["educator"]["username"] = educator_username
101105

102106
return self._update_from_dict(ret)
103107
return success
@@ -136,7 +140,7 @@ def student_names(self, *, page=1) -> list[str]:
136140
response = requests.get(f"https://scratch.mit.edu/classes/{self.id}/")
137141
soup = BeautifulSoup(response.text, "html.parser")
138142
found = set("")
139-
143+
140144
for result in soup.css.select("ul.scroll-content .user a"):
141145
result_text = result.text.strip()
142146
if result_text in found:
@@ -185,7 +189,7 @@ def class_studio_ids(self, *, page: int = 1) -> list[int]:
185189
ret = []
186190
response = requests.get(f"https://scratch.mit.edu/classes/{self.id}/")
187191
soup = BeautifulSoup(response.text, "html.parser")
188-
192+
189193
for result in soup.css.select("ul.scroll-content .gallery a[href]:not([class])"):
190194
value = result["href"]
191195
if not isinstance(value, str):

scratchattach/site/session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def enforce_ratelimit(__type: str, name: str, amount: int = 5, duration: int = 6
4949
cache = ratelimit_cache
5050
cache.setdefault(__type, [])
5151
uses = cache[__type]
52-
while uses[-1] < time.time() - duration:
52+
while uses and uses[-1] < time.time() - duration:
5353
uses.pop()
5454
if len(uses) < amount:
5555
uses.insert(0, time.time())
@@ -94,6 +94,7 @@ class Session(BaseSiteComponent):
9494

9595
has_outstanding_email_confirmation: bool = field(repr=False, default=False)
9696
is_teacher: bool = field(repr=False, default=False)
97+
is_teacher_invitee: bool = field(repr=False, default=False)
9798
_session: Optional[Session] = field(kw_only=True, default=None)
9899

99100
def __str__(self) -> str:
@@ -139,6 +140,7 @@ def _update_from_dict(self, data: Union[dict, typed_dicts.SessionDict]):
139140

140141
self.new_scratcher = data["permissions"]["new_scratcher"]
141142
self.is_teacher = data["permissions"]["educator"]
143+
self.is_teacher_invitee = data["permissions"]["educator_invitee"]
142144

143145
self.mute_status = data["permissions"]["mute_status"]
144146

scratchattach/site/typed_dicts.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from scratchattach.cloud import _base
4-
from typing import TypedDict, Union, Optional
4+
from typing import TypedDict, Union, Optional, Required, NotRequired
55

66
class SessionUserDict(TypedDict):
77
id: int
@@ -67,11 +67,11 @@ class UserProfileDict(TypedDict):
6767
images: dict[str, str]
6868

6969
class UserDict(TypedDict):
70-
id: int
71-
username: str
72-
scratchteam: bool
73-
history: UserHistoryDict
74-
profile: UserProfileDict
70+
id: NotRequired[int]
71+
username: NotRequired[str]
72+
scratchteam: NotRequired[bool]
73+
history: NotRequired[UserHistoryDict]
74+
profile: NotRequired[UserProfileDict]
7575

7676
class CloudLogActivityDict(TypedDict):
7777
user: str
@@ -93,7 +93,8 @@ class ClassroomDict(TypedDict):
9393
title: str
9494
description: str
9595
status: str
96-
date_start: str
97-
date_end: Optional[str]
98-
images: dict[str, str]
96+
date_start: NotRequired[str]
97+
date_end: NotRequired[Optional[str]]
98+
images: NotRequired[dict[str, str]]
9999
educator: UserDict
100+
is_closed: NotRequired[bool]

tests/test_editor_obfuscation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ def test_project():
2323
body.export("obfuscated.sb3")
2424

2525

26-
2726
if __name__ == '__main__':
2827
test_project()

tests/util/auth.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
note = "gAAAAABozoVANH3_fARiCOFvv-O6pHd8DU2kb5vzs7xIxzE3JoWnsFByK5LdoLnnfh0pXpmSpo0KS1j4uwl3XvF-Qm3Sm63Fwy_H224EAdqF_d2hWdVxJkn7HmAJTT445AyrtdFYgrg9"
88

99
[auth]
10-
scratchattachv2="gAAAAABozo75u7Eov4zakrObMqLVs6wmwSNXQ7KroU5ntU7vZvM49fW-RnEWl1ZCnqIxAnjsPW5OUOBO2IS_MJYfuRl2CVNtaJojaO1s0uHk8_vZhh_YVMI="
10+
scratchattachv2 = "gAAAAABozo75u7Eov4zakrObMqLVs6wmwSNXQ7KroU5ntU7vZvM49fW-RnEWl1ZCnqIxAnjsPW5OUOBO2IS_MJYfuRl2CVNtaJojaO1s0uHk8_vZhh_YVMI="
11+
12+
[teacher_auth]
13+
username = "gAAAAABo2AwGrm5MsCqFTz7yPBZf8F--b3529aCsi9olynL0DKBi5EllZR1jNtsTt4vUPdke7eyEHBToMfN00QgxAU4RmlH3GCAK4TpXs7Qd7eI4iGD1hIU="
14+
password = "gAAAAABo2AwLc-oRH45T6V-xlcpbaqH4Ds93nMCrMbgUv_AHoQhTO1L7NkU54npm54-Zjs7YVlkOSFS5kffWzJeMZB7maNAv1WKnHJ4YvzF_R7PlIaeIBa8="

0 commit comments

Comments
 (0)