Skip to main content

A Python library with functions to scrape data from Scratch.mit.edu

Project description

Catscrape

Catscrape is a library with web scraping functions for the popular beginner programming website Scratch.mit.edu. It can extract data from followers, studios, and soon extract hearts, stars, and remix counts for projects.

Functionality

This library is new, so most features are on the to-do list. Here are the supported and planned features:

Data to Extract Support
User followers ✅Supported
User following ✅Supported
Get user "About Me" 🟨Coming Soon
Get user shared projects 🟨Coming Soon
Studio curators ✅Supported
Auto invite to studio ✅Supported
Project hearts 🟨Coming Soon
Project stars 🟨Coming Soon
Project remixes 🟨Coming Soon
Project viewes 🟨Coming Soon
Anything else 🟥Not Supported

Installation

The library can be installed via pip install:

pip install catscrape

Documentation

Scratcher

The Scratcher class has methods to get the number of followers and the number of users the user is following. They are all listed below. A Scratcher object can be initalized as shown below. In the example code, it is assumed a variable named user is assigned to a Scratcher object.

>>> import catscrape
>>> user = catscrape.Scratcher("CrystalKeeper7")

All of the methods can be passed a verbose argument, which controls various print statements to assure the user of progress.

All of the methods cache their outputs. For example, if Scratcher.follower_count is executed, Scratcher.get_followers will return instantly with the already-computed value. The Scratcher.is_following and Scratcher.is_followed_by methods do not generate a cache because they return as soon as the value is found and do not find all of the followers or following.

get_followers

The Scratcher.get_followers method returns a list of the the followers of the user:

>>> followers = user.get_followers()
>>> type(followers)
<class 'list'>
>>> type(followers[0])
<class 'str'>

get_following

The Scratcher.get_following method returns a list of the users that the user is following:

>>> following = user.get_following()
>>> type(followers)
<class 'list'>
>>> type(followers[0])
<class 'str'>

is_following

The Scratcher.is_following method has a parameter username, and returns whether the user is following that username.

>>> is_following_griffpatch = user.is_following("griffpatch")
>>> type(is_following_griffpatch)
<class 'bool'>

is_followed_by

The inverse of the Scratcher.is_following method, returning whether the user is followed by the given username.

>>> is_following_griffpatch = user.is_following("griffpatch")
>>> type(is_following_griffpatch)
<class 'bool'>

follower_count

Returns the follower count of the user.

>>> num_followers = user.follower_count()
>>> type(num_followers)
<class 'int'>

following_count

Returns the number of scratchers the user is following.

>>> num_followers = user.follower_count()
>>> type(num_followers)
<class 'int'>

Providing Login

The Studio.invite_curators method requires an account with manager or host authority to invite curators. The save_login_data function saves the login data of an account. The data is saved in a pickle file in a folder in the appdata folder of the computer. Example usage is shown below:

>>> from catscrape import save_login_data
>>> save_login_data("<username>", "<password>")
Successfully saved the login data.

Studio

The Studio class has methods to get the curators of the studio, and to auto-invite curators. Below is an example of initalizing the studio class. The one parameter is the studio id.

>>> from catscrape import Studio
>>> studio = Studio(45693845)

get_curators

The Studio.get_curators method returns all of the curators of the studio. Becuase it has to physically scroll through the curators using selenium (headless, of course), this function tends to take longer. The scroll_wait_time parameter adjusts the amount of time to wait after pressing the "Load More" button to press it again. Changing this too low causes instability in results, possibly leading to incorrect results, with too few curators.

>>> curators = studio.get_curators(
...     scroll_wait_time=0.25 # More reliable, but slower
... )
>>> type(curators)
<class 'list'>
>>> type(curators[0])
<class 'str'>

invite_curators

The Studio.invite_curators method invites curators to the studio. Login info is required for this. See "Providing Login" above. The usernames to invite should be passed to the method. A physical Chrome window will open, and will be controlled by selenium to login and invite the curators. Warning: I have experienced failure to invite more users after about 100-150 invites in a row. Try to limit the number of usernames to invite in a batch to below this value to avoid partial failure.

>>> invitees = ["griffpatch", "CrystalKeeper7", "DominoKid11", "username4"]
>>> studio.invite_curators(
...     usernames=invitees
... )
<invites curators>

Versions

1.1.0

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

catscrape-1.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

catscrape-1.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file catscrape-1.1.0.tar.gz.

File metadata

  • Download URL: catscrape-1.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for catscrape-1.1.0.tar.gz
Algorithm Hash digest
SHA256 5f9aa6c532c5e5f152f70ad6164cd62ae5f705feff0e22a661e3e0ffa6a6783c
MD5 89466ca038f12305f21b06f07362db66
BLAKE2b-256 41b2d813ee2cfce2cfffd3ef0a2a68213eac45413de0a635702c1b5b026df208

See more details on using hashes here.

File details

Details for the file catscrape-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: catscrape-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for catscrape-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bef308da2c4cb1394fad5e1abc1adbbcf685e7d7c672db6da8f0a57b8a5830bf
MD5 e4e1bd1c9062ddb93dd34816a77b45d2
BLAKE2b-256 55153086460383bfd80b3dc7115500d37068f03de80a515e960c72c39560b203

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page