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

Method mystuff_counts

scratchattach/site/session.py:780–806  ·  view source on GitHub ↗

Gets the number of shared projects, unshared projects, and studios as listed on the mystuff page, and returns them in that order. Example usage: shared, unshared, studios = sess.mystuff_counts() print(f"You have {shared} shared projects, {unshared} unshared

(self)

Source from the content-addressed store, hash-verified

778 # --- My stuff page ---
779
780 def mystuff_counts(self) -> tuple[int, int, int]:
781 """
782 Gets the number of shared projects, unshared projects, and studios as listed on the mystuff page,
783 and returns them in that order.
784
785 Example usage:
786 shared, unshared, studios = sess.mystuff_counts()
787 print(f"You have {shared} shared projects, {unshared} unshared projects, and are in {studios} studios")
788 """
789 # TODO: classrooms?
790 with requests.no_error_handling():
791 resp = requests.get("https://scratch.mit.edu/mystuff/", headers=self._headers, cookies=self._cookies)
792 soup = bs4.BeautifulSoup(resp.text, "html.parser")
793
794 shared_elem = soup.select_one("span[data-content='shared-count']")
795 unshared_elem = soup.select_one("span[data-content='unshared-count']")
796 gallery_elem = soup.select_one("span[data-content='gallery-count']")
797
798 assert shared_elem is not None
799 assert unshared_elem is not None
800 assert gallery_elem is not None
801
802 shared: str = shared_elem.text.strip()
803 unshared: str = unshared_elem.text.strip()
804 gallery: str = gallery_elem.text.strip()
805
806 return int(shared), int(unshared), int(gallery)
807
808 def mystuff_projects(
809 self, filter_arg: str = "all", *, page: int = 1, sort_by: str = "", descending: bool = True

Callers 1

test_sessionFunction · 0.80

Calls 2

no_error_handlingMethod · 0.45
getMethod · 0.45

Tested by 1

test_sessionFunction · 0.64