Skip to main content

Scrape Rotten Tomatoes's website for basic information on movies, without the use of their hard-to-attain official REST API.

Project description

Rotten Tomatoes in Python

This package allows you to easily fetch Rotten Tomatoes scores and other movie data such as genres, without the use of the official Rotten Tomatoes API. The package scrapes their website for the data. I built this because unfortunately, to get access to their API, you have to submit a special request which takes an inordinate amount of time to process, or doesn't go through at all.

Usage

You can either call the standalone functions tomatometer, audience_score, genres, etc., or use the Movie class to only pass the name and have each attribute be fetched automatically. If you use the Movie class, you can print all attributes by printing the object itself, or by accessing each attribute individually.

The weighted score is calculated using the formula $\frac{2}{3}(tomatometer) + \frac{1}{3}(audience)$. The result is then rounded to the nearest integer.

Basic usage examples:

import rottentomatoes_python as rt

print(rt.tomatometer("happy gilmore"))
# Output: 61
# Type: int

print(rt.audience_score('top gun maverick'))
# Output: 99
# Type: int

print(rt.rating('everything everywhere all at once'))
# Output: R
# Type: str

print(rt.genres('top gun'))
# Output: ['Action', 'Adventure']
# Type: list[str]

print(rt.weighted_score('happy gilmore'))
# Output: 69
# Type: int

print(rt.year_released('happy gilmore'))
# Output: 1996
# Type: str

print(rt.actors('top gun maverick', max_actors=5))
# Output: ['Tom Cruise', 'Miles Teller', 'Jennifer Connelly', 'Jon Hamm', 'Glen Powell']
# Type: list[str]

# --- Using the Movie class ---
movie = rt.Movie('top gun')
print(movie)
# Output
    # Top Gun, PG, 1h 49m.
    # Released in 1986.
    # Tomatometer: 58
    # Weighted score: 66
    # Audience Score: 83
    # Genres - ['Action', 'Adventure']
    # Prominent actors: Tom Cruise, Kelly McGillis, Anthony Edwards, Val Kilmer, Tom Skerritt.
# Type: str

print(movie.weighted_score)
# Output: 66
# Type: int

Exceptions

If you're using this package within a larger program, it's useful to know what exceptions are raised (and when) so they can be caught and handled.

LookupError

When any call is made to scrape the Rotten Tomatoes website (Tomatometer, Audience Score, Genres, etc.), if a proper movie page wasn't returned (can be due to a typo in name entry, duplicate movie names, etc.), a LookupError is raised, printing the attempted query url.

Performance

v0.3.0 makes 19x more efficient that the previous release, v0.2.5. Data attained from scraping Rotten Tomatoes is temporarily cached and used to parse various other attributes. To test the performance difference, I used two separate virtual environments, old and venv. rottentomatoes-python==0.2.5 was installed on old, and rottentomatoes-python==0.3.0 was installed on venv. I then ran the same script, shown below, using each environment (Python 3.10.4).

import rottentomatoes as rt
from time import perf_counter


def test() -> None:
    start = perf_counter()
    movie = rt.Movie('top gun maverick')
    print('\n', movie, sep='')
    print(f"That took {perf_counter() - start} seconds.")


if __name__ == "__main__":
    test()

The results:

❯ deactivate && source old/bin/activate && python test.py

Top Gun Maverick, PG-13, 2h 11m.
Released in 2022.
Tomatometer: 97
Weighted score: 97
Audience Score: 99
Genres - ['Action', 'Adventure']

That took 6.506246249999094 seconds.
❯ deactivate && source venv/bin/activate && python test.py

Top Gun Maverick, PG-13, 2h 11m.
Released in 2022.
Tomatometer: 97
Weighted score: 97
Audience Score: 99
Genres - ['Action', 'Adventure']
Prominent actors: Tom Cruise, Miles Teller, Jennifer Connelly, Jon Hamm, Glen Powell.

That took 0.3400420409961953 seconds.

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

rottentomatoes-python-0.3.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

rottentomatoes_python-0.3.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file rottentomatoes-python-0.3.2.tar.gz.

File metadata

  • Download URL: rottentomatoes-python-0.3.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for rottentomatoes-python-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c32024df521bfc2c0a2c66c0652253f80ff769ca748a0b490cfed616d4689c8f
MD5 556dd62881605497ab2ba9dfcc5691b7
BLAKE2b-256 c05a5f527e90b8e3c4a9266870a3586f8f162c671fb7796daae6d83a3a6f97de

See more details on using hashes here.

File details

Details for the file rottentomatoes_python-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: rottentomatoes_python-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for rottentomatoes_python-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2ea1b2e8cdf036868fd14dc0a10750ec05d82c60e06fe7af366f0eb2255b87f1
MD5 12d9ceec29bdaf7e6e760930f130f39e
BLAKE2b-256 21aa29739730dc8b72b5c9460413610cebd77067d25f9038c661e8e2791db5a7

See more details on using hashes here.

Supported by

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