|
26 | 26 | dt_from_isoformat, |
27 | 27 | temporary_httpclient, |
28 | 28 | page_api_iterative, |
| 29 | + page_html_iterative, |
29 | 30 | split |
30 | 31 | ) |
31 | 32 | from ..utils.client import HTTPClient |
@@ -228,45 +229,60 @@ async def create_class_studio(self,title:str,description:str|None=None) -> Studi |
228 | 229 | studio.title = data.get("gallery_title") |
229 | 230 | return studio |
230 | 231 |
|
231 | | - async def get_class_studios(self,start_page:int|None=None,end_page:int|None=None) -> AsyncGenerator[Studio]: |
| 232 | + async def get_class_studios(self,start_page:int|None=None,end_page:int|None=None,*,use_api:bool=False) -> AsyncGenerator[Studio]: |
232 | 233 | """ |
233 | 234 | クラスのスタジオを取得する。 |
234 | 235 |
|
235 | 236 | Args: |
236 | 237 | start_page (int|None, optional): 取得するスタジオの開始ページ位置。初期値は1です。 |
237 | 238 | end_page (int|None, optional): 取得するスタジオの終了ページ位置。初期値はstart_pageの値です。 |
| 239 | + use_api (bool, optional): 教師向けAPIを使用するか。教師の場合のみ使用できます。 |
238 | 240 |
|
239 | 241 | Yields: |
240 | 242 | Studio: 取得したスタジオ |
241 | 243 | """ |
242 | | - self.require_session() |
243 | | - async for _s in page_api_iterative( |
244 | | - self.client,f"https://scratch.mit.edu/site-api/classrooms/studios/{self.id}/", |
245 | | - start_page,end_page |
246 | | - ): |
247 | | - _s:OldAnyObjectPayload[OldStudioPayload] |
248 | | - yield Studio._create_from_data(_s["pk"],_s["fields"],self.client_or_session,Studio._update_from_old_data) |
| 244 | + if use_api: |
| 245 | + self.require_session() |
| 246 | + async for _s in page_api_iterative( |
| 247 | + self.client,f"https://scratch.mit.edu/site-api/classrooms/studios/{self.id}/", |
| 248 | + start_page,end_page |
| 249 | + ): |
| 250 | + yield Studio._create_from_data(_s["pk"],_s["fields"],self.client_or_session,Studio._update_from_old_data) |
| 251 | + else: |
| 252 | + async for _t in page_html_iterative( |
| 253 | + self.client,f"https://scratch.mit.edu/classes/{self.id}/studios/", |
| 254 | + start_page,end_page,list_class="gallery thumb item" |
| 255 | + ): |
| 256 | + yield Studio._create_from_html(_t,self.client_or_session,host=self.educator) |
249 | 257 |
|
250 | | - async def get_class_students(self,start_page:int|None=None,end_page:int|None=None) -> AsyncGenerator[User]: |
| 258 | + async def get_students(self,start_page:int|None=None,end_page:int|None=None,*,use_api:bool=False) -> AsyncGenerator[User]: |
251 | 259 | """ |
252 | 260 | クラスの生徒を取得する。 |
253 | 261 |
|
254 | 262 | Args: |
255 | 263 | start_page (int|None, optional): 取得するユーザーの開始ページ位置。初期値は1です。 |
256 | 264 | end_page (int|None, optional): 取得するユーザーの終了ページ位置。初期値はstart_pageの値です。 |
| 265 | + use_api (bool, optional): 教師向けAPIを使用するか。教師の場合のみ使用できます。 |
257 | 266 |
|
258 | 267 | Yields: |
259 | 268 | User: 取得したユーザー |
260 | 269 | """ |
261 | | - self.require_session() |
262 | | - async for _u in page_api_iterative( |
263 | | - self.client,f"https://scratch.mit.edu/site-api/classrooms/students/{self.id}/", |
264 | | - start_page,end_page |
265 | | - ): |
266 | | - _u:OldAnyObjectPayload[StudentPayload] |
267 | | - yield User._create_from_data(_u["fields"]["user"]["username"],_u["fields"],self.client_or_session,User._update_from_student_data) |
| 270 | + if use_api: |
| 271 | + self.require_session() |
| 272 | + async for _u in page_api_iterative( |
| 273 | + self.client,f"https://scratch.mit.edu/site-api/classrooms/students/{self.id}/", |
| 274 | + start_page,end_page |
| 275 | + ): |
| 276 | + _u:OldAnyObjectPayload[StudentPayload] |
| 277 | + yield User._create_from_data(_u["fields"]["user"]["username"],_u["fields"],self.client_or_session,User._update_from_student_data) |
| 278 | + else: |
| 279 | + async for _t in page_html_iterative( |
| 280 | + self.client,f"https://scratch.mit.edu/classes/{self.id}/students/", |
| 281 | + start_page,end_page,list_class="user thumb item" |
| 282 | + ): |
| 283 | + yield User._create_from_html(_t,self.client_or_session) |
268 | 284 |
|
269 | | - async def get_class_activity( |
| 285 | + async def get_privete_activity( |
270 | 286 | self, |
271 | 287 | start_page:int|None=None, |
272 | 288 | end_page:int|None=None, |
|
0 commit comments