| 94 | self._json_headers["Content-Type"] = "application/json" |
| 95 | |
| 96 | def _update_from_dict(self, data: ProjectDict): |
| 97 | self.id = int(data.get("id", self.id)) |
| 98 | self.url = f"https://scratch.mit.edu/projects/{self.id}" |
| 99 | if author := data.get("author"): |
| 100 | self.author_name = author.get("username", self.author_name) |
| 101 | self.author_name = data.get("username", self.author_name) |
| 102 | self.comments_allowed = data.get("comments_allowed", self.comments_allowed) |
| 103 | self.instructions = data.get("instructions", self.instructions) |
| 104 | self.notes = data.get("description", self.notes) |
| 105 | |
| 106 | if history := data.get("history"): |
| 107 | self.created = history.get("created", self.created) |
| 108 | self.last_modified = history.get("modified", self.last_modified) |
| 109 | self.share_date = history.get("shared", self.share_date) |
| 110 | |
| 111 | self.thumbnail_url = data.get("image", self.thumbnail_url) |
| 112 | |
| 113 | # NOTE: if we have no value, then we set it to None instead of empty string. |
| 114 | # TODO: consider changing this behavior |
| 115 | remix_data = data.get("remix", {}) |
| 116 | self.remix_parent = remix_data.get("parent") |
| 117 | self.remix_root = remix_data.get("root") |
| 118 | |
| 119 | if stats := data.get("stats"): |
| 120 | self.favorites = stats.get("favorites", self.favorites) |
| 121 | self.loves = stats.get("loves", self.loves) |
| 122 | self.remix_count = stats.get("remixes", self.remix_count) |
| 123 | self.views = stats.get("views", self.views) |
| 124 | |
| 125 | self.title = data.get("title", self.title) |
| 126 | self.project_token = data.get("project_token", None) |
| 127 | |
| 128 | # the typed dict here isn't perfect: |
| 129 | # code as in {"code": "not found"} |
| 130 | # if the project is unshared, then we get that error code |
| 131 | return "code" not in data |
| 132 | |
| 133 | def __rich__(self): |
| 134 | from rich.panel import Panel |