MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / raw_json

Method raw_json

scratchattach/site/project.py:330–357  ·  view source on GitHub ↗

Method only works for project created with Scratch 3. Returns: dict: The raw project JSON as decoded Python dictionary

(self)

Source from the content-addressed store, hash-verified

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()

Callers 5

bodyMethod · 0.95
raw_json_or_emptyMethod · 0.95
creator_agentMethod · 0.95
upload_json_fromMethod · 0.80

Calls 4

jsonMethod · 0.80
updateMethod · 0.45
no_error_handlingMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected