Method only works for project created with Scratch 3. Returns: dict: The raw project JSON as decoded Python dictionary
(self)
| 328 | return editor.Project.from_json(raw_json) |
| 329 | |
| 330 | def raw_json(self): |
| 331 | """ |
| 332 | Method only works for project created with Scratch 3. |
| 333 | |
| 334 | Returns: |
| 335 | dict: The raw project JSON as decoded Python dictionary |
| 336 | """ |
| 337 | try: |
| 338 | self.update() |
| 339 | |
| 340 | except Exception as e: |
| 341 | raise (exceptions.FetchError(f"You're not authorized for accessing {self}.\nException: {e}")) |
| 342 | |
| 343 | with requests.no_error_handling(): |
| 344 | resp = requests.get( |
| 345 | f"https://projects.scratch.mit.edu/{self.id}?token={self.project_token}", |
| 346 | timeout=10, |
| 347 | ) |
| 348 | |
| 349 | try: |
| 350 | return resp.json() |
| 351 | except json.JSONDecodeError: |
| 352 | # I am not aware of any cases where this will not be a zip file |
| 353 | # in the future, cache a projectbody object here and just return the json |
| 354 | # that is fetched from there to not waste existing asset data from this zip file |
| 355 | |
| 356 | with zipfile.ZipFile(BytesIO(resp.content)) as zipf: |
| 357 | return json.load(zipf.open("project.json")) |
| 358 | |
| 359 | def raw_json_or_empty(self): |
| 360 | return self.raw_json() |
no test coverage detected