@@ -47,9 +47,6 @@ def __init__(self, **entries) -> None:
4747 self .parent_title = None
4848 self ._moderation_status = None
4949
50- self .remix_tree_children : Optional [list [Project ]] = None
51- self .remix_tree_parent : Optional [Project ] = None
52-
5350 # Update attributes from entries dict:
5451 self .__dict__ .update (entries )
5552
@@ -289,10 +286,6 @@ class Project(PartialProject):
289286
290287 :.thumbnail_url:
291288
292- :.remix_parent:
293-
294- :.remix_root:
295-
296289 :.loves: The project's love count
297290
298291 :.favorites: The project's favorite count
@@ -860,103 +853,6 @@ def visibility(self):
860853 return requests .get (f"https://api.scratch.mit.edu/users/{ self ._session .username } /projects/{ self .id } /visibility" ,
861854 headers = self ._headers , cookies = self ._cookies ).json ()
862855
863- def remix_tree (self ) -> Project :
864- """
865- Fetch & cache remix tree, and return remix root.
866- Cached remix tree children accessible via Project.remix_tree_children.
867- A parent project object that is linked to children is accessible via Project.remix_tree_parent
868-
869- :return remix root project. All remixes in the tree are (in)directly linked.
870- """
871-
872- data : dict = requests .get (f"https://scratch.mit.edu/projects/{ self .id } /remixtree/bare/" ).json ()
873-
874- mapping : dict [str , Project ] = {}
875- root_id = data .pop ("root_id" )
876-
877-
878- # load up all projects
879- for curr_id , curr_data in data .items ():
880- curr_data = data [curr_id ]
881- if share_date := curr_data ["datetime_shared" ]:
882- share_date = share_date ["$date" ] / 1000
883-
884- if curr_id == str (self .id ):
885- curr_obj = self
886- else :
887- curr_obj = Project (id = curr_id )
888-
889- curr_obj .title = curr_data ["title" ]
890- curr_obj .author_name = curr_data ["username" ]
891- curr_obj .favorites = curr_data ["favorite_count" ]
892- curr_obj .loves = curr_data ["love_count" ]
893- curr_obj ._moderation_status = curr_data ["moderation_status" ]
894- curr_obj .share_date = share_date # timestamp
895- curr_obj .created = curr_data ["datetime_created" ]["$date" ] / 1000
896- curr_obj .last_modified = curr_data ["mtime" ]["$date" ] / 1000
897- curr_obj ._session = self ._session
898- curr_obj .remix_tree_children = []
899-
900- # curr_obj._visibility=curr_data["visibility"]
901- # is_published=curr_data["is_published"]
902- # curr_obj.ctime = curr_data["ctime"]["$date"] / 1000
903-
904- mapping [curr_id ] = curr_obj
905-
906- assert self in mapping .values ()
907-
908- # link projects
909- for curr_id , curr_data in data .items ():
910- curr_data = data [curr_id ]
911- curr_obj = mapping [curr_id ]
912-
913- parent_id = curr_data ["parent_id" ]
914- if parent := mapping .get (parent_id ):
915- curr_obj .remix_tree_parent = parent
916- # parent cannot be None, as it is the if condition
917- parent .remix_tree_children .append (curr_obj ) # type: ignore
918-
919- return mapping [root_id ]
920-
921- def remix_tree_pretty (self , indent : int = 0 , * , formatter : Optional [Callable [[Project , int ], str ]] = None ):
922- """
923- Prettily formats and indents the remix tree attached to this project. (does NOT start at root)
924- :param indent: default indent - recommend keeping this as 0
925- :param formatter: function that formats a single project with an indent. Return a string. Recommend starting with '\t ' * indent
926- :return: Large string containing the formatted remix tree. For large trees, it is recommended to save it to a file.
927- """
928- if not formatter :
929- formatter = lambda p , ind : f"{ '\t ' * ind } -P { p .title } ({ p .id } ) #{ p .remix_depth } \n "
930-
931- if self .remix_tree_children is None :
932- self .remix_tree ()
933-
934- assert isinstance (self .remix_tree_children , list )
935-
936- ret = formatter (self , indent )
937- for child in self .remix_tree_children :
938- ret += child .remix_tree_pretty (indent + 1 , formatter = formatter )
939-
940- return ret
941-
942- @property
943- def remix_depth (self ) -> int :
944- """
945- Get the 'remix depth' of this project - i.e. the number of layers of remixing until one reaches the remix root.
946- """
947- if self .remix_tree_children is None :
948- self .remix_tree ()
949-
950- depth = 0
951- p = self
952- while p .remix_tree_parent :
953- # this could also be done recursively, but it can hit the recursion limit in extreme cases
954- # > and this happens often, because of remix chains
955- p = p .remix_tree_parent
956- depth += 1
957-
958- return depth
959-
960856
961857# ------ #
962858
0 commit comments