Skip to main content

Python scraper for accessing ratings from tvbythenumbers.zap2it.com

Project description

py_zap is a Python scraper for fetching daily broadcast and cable ratings from tvbythenumbers.zap2it.com.

Installation

To install with pip:

>>> pip install py_zap

Or clone this repository and run:

>>> python setup.py install

Broadcast Ratings

Let’s fetch the final broadcast ratings for October 27, 2016.

  • If no date parameter is included, it will default to yesterday’s date

>>> from py_zap import Broadcast
>>> ratings = Broadcast('October 27, 2016')
  • Now we can look at the chart entries:

>>> entry = ratings[0]     # Gives the 1st entry
>>> entry.show             # Get the name of the show
'The Big Bang Theory'
>>> entry.viewers          # Get the number of viewers (in millions)
14.3
>>> entry.rating           # Get the rating (percentage)
3.4
  • We can also print out the whole chart by:

>>> print(ratings)
>>>
Final Broadcast Ratings for Thursday, October 27 2016
|Show                          |Time      |Network|Viewers|Rating |Share  |
+-------------------------------------------------------------------------+
|The Big Bang Theory           |    8 p.m.|    CBS|   14.3|    3.4|   13.0|
|Grey’s Anatomy                |    8 p.m.|    ABC|    8.2|    2.2|    8.0|
|Superstore                    |    8 p.m.|    NBC|    4.2|    1.3|    5.0|
|Rosewood                      |    8 p.m.|    FOX|    3.4|    0.8|    3.0|
|Legends of Tomorrow           |    8 p.m.| The CW|    1.8|    0.6|    2.0|
|The Great Indoors             | 8:30 p.m.|    CBS|    8.8|    1.9|    7.0|
|The Good Place                | 8:30 p.m.|    NBC|    3.9|    1.2|    4.0|
|Mom                           |    9 p.m.|    CBS|    7.0|    1.5|    5.0|
|Chicago Med                   |    9 p.m.|    NBC|    7.1|    1.5|    5.0|
|Notorious                     |    9 p.m.|    ABC|    3.8|    0.8|    3.0|
|Pitch                         |    9 p.m.|    FOX|    2.9|    0.8|    3.0|
|Supernatural                  |    9 p.m.| The CW|    1.7|    0.6|    2.0|
|Life in Pieces                | 9:30 p.m.|    CBS|    6.0|    1.4|    5.0|
|Pure Genius                   |   10 p.m.|    CBS|    6.2|    1.0|    4.0|
|The Blacklist                 |   10 p.m.|    NBC|    5.5|    1.2|    4.0|
|How to Get Away with Murder   |   10 p.m.|    ABC|    4.1|    1.2|    4.0|

By default, the final broadcast ratings are fetched. To access the fast ratings, which are posted earlier but less accurate, set ‘final’ param to False. If there are no final ratings available, it will redirect to fast access ratings.

>>> ratings = Broadcast('October 27, 2016', final=False)

Cable Ratings

To fetch the cable ratings for October 27, 2016:

>>> from py_zap import Cable
>>> ratings = Cable('October 27, 2016')

Other things you can do

Sort chart results

  • Broadcast or cable ratings can be sorted based on show, net, time, rating, or viewers

  • Broadcast ratings only can be sorted on share

>>> ratings = Cable('October 27, 2016').sort('viewers')    # Sort cable ratings by viewers
>>> ratings = Broadcast('October 27, 2016').sort('share')  # Sort broadcast ratings by share (broadcast only)

Fetch specific shows or networks

  • Pass a list if you want to fetch more than one

>>> ratings = Broadcast('October 27, 2016', show='Supernatural')     # Fetch a specific show
>>> ratings = Broadcast('October 27, 2016', network=['CBS', 'NBC'])  # Fetch a specific network

Iterate through multiple weeks

>>> next_week = ratings.get_next_week()  # Get next week's date
>>> last_week = ratings.get_last_week()  # Get last week's date

Get network averages (broadcast only)

>>> averages = ratings.get_averages()  # Get the ratings/viewers averages for broadcast networks
>>> averages['NBC']
{'rating': 1.3, 'viewers': 5.56, 'share': 5.0}

Dependencies

License

  • This project is under the MIT License.

  • All content is owned by Tribune Media Company. See zap2it.com’s Terms of Service for more details.

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

py_zap-1.2.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distributions

py_zap-1.2.2-py3.7.egg (27.9 kB view details)

Uploaded Source

py_zap-1.2.2-py2.py3-none-any.whl (13.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file py_zap-1.2.2.tar.gz.

File metadata

  • Download URL: py_zap-1.2.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for py_zap-1.2.2.tar.gz
Algorithm Hash digest
SHA256 7f2bbee78bdff4d9c6a1262e187990e4d16aab646ded28554133d4ad09b1111f
MD5 f5e71f0f81b5ecae2337dbcfa523d677
BLAKE2b-256 36e7583b8a01b5834684779203558bd5f167152fa69aff6fab636b24066f9554

See more details on using hashes here.

File details

Details for the file py_zap-1.2.2-py3.7.egg.

File metadata

  • Download URL: py_zap-1.2.2-py3.7.egg
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for py_zap-1.2.2-py3.7.egg
Algorithm Hash digest
SHA256 1988f9b27807dc5f0b3718d938db4d0e5cfbed45221caecbe0aa3c415d8008cb
MD5 9dec54809c2bece422160711c82a48f5
BLAKE2b-256 024a83d7223d9f3b57a19856d057b51dff80e5e8b1941831f425bccec6939c16

See more details on using hashes here.

File details

Details for the file py_zap-1.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: py_zap-1.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for py_zap-1.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a1e75c079732f1978ddf0c8f531b35cf90c83069017a2f822a005b13b61729c4
MD5 87e9d1a5e8f8da09a614b30602b68408
BLAKE2b-256 34c400c4954b83e717408cb27c778937c0072d17830f695e133417f090862dd4

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