Downloads the project json to the given directory. Args: filename (str): The name that will be given to the downloaded file. dir (str): The path of the directory the file will be saved in.
(self, *, filename=None, dir=".")
| 278 | # -- Project contents (body/json) -- # |
| 279 | |
| 280 | def download(self, *, filename=None, dir="."): |
| 281 | """ |
| 282 | Downloads the project json to the given directory. |
| 283 | |
| 284 | Args: |
| 285 | filename (str): The name that will be given to the downloaded file. |
| 286 | dir (str): The path of the directory the file will be saved in. |
| 287 | """ |
| 288 | try: |
| 289 | if filename is None: |
| 290 | filename = str(self.id) |
| 291 | if not (dir.endswith("/") or dir.endswith("\\")): |
| 292 | dir += "/" |
| 293 | self.update() |
| 294 | response = requests.get( |
| 295 | f"https://projects.scratch.mit.edu/{self.id}?token={self.project_token}", |
| 296 | timeout=10, |
| 297 | ) |
| 298 | filename = filename.removesuffix(".sb3") |
| 299 | with open(f"{dir}{filename}.sb3", "wb") as f: |
| 300 | f.write(response.content) |
| 301 | except Exception as exc: |
| 302 | raise (exceptions.FetchError("Method only works for projects created with Scratch 3")) from exc |
| 303 | |
| 304 | @deprecated("Use raw_json instead") |
| 305 | def get_json(self) -> str: |