GithubHelp home page GithubHelp logo

mbellogularte / billboard-charts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from guoguo12/billboard-charts

0.0 0.0 0.0 132 KB

Python API for downloading Billboard charts.

Home Page: https://pypi.python.org/pypi/billboard.py

License: MIT License

Python 99.58% Shell 0.42%

billboard-charts's Introduction

billboard.py

Build Status

billboard.py is a Python API for accessing music charts from Billboard.com.

Installation

To install with pip, run

pip install billboard.py

You can also clone this repository and run python setup.py install.

Quickstart

To download a Billboard chart, we use the ChartData() constructor.

Let's fetch the current Hot 100 chart.

>>> import billboard
>>> chart = billboard.ChartData('hot-100')

Now we can look at the chart entries, which are of type ChartEntry and have attributes like artist and title:

>>> song = chart[0]  # Get no. 1 song on chart
>>> song.title
'Nice For What'
>>> song.artist
'Drake'
>>> song.weeks  # Number of weeks on chart
2

We can also print the entire chart:

>>> print(chart)
hot-100 chart from 2018-04-28
-----------------------------
1. 'Nice For What' by Drake
2. 'God's Plan' by Drake
3. 'Meant To Be' by Bebe Rexha & Florida Georgia Line
4. 'Psycho' by Post Malone Featuring Ty Dolla $ign
5. 'The Middle' by Zedd, Maren Morris & Grey
# ...

Guide

Downloading a chart

Use the ChartData constructor to download a chart:

ChartData(name, date=None, fetch=True, timeout=25)

The arguments are:

  • name – The chart name, e.g. 'hot-100' or 'pop-songs'. You can browse the Charts page on Billboard.com to find valid chart names; the URL of a chart will look like http://www.billboard.com/charts/CHART-NAME (example). Almost any chart should work; the only chart known not to work is spotify-rewind.
  • date – The chart date as a string, in YYYY-MM-DD format. By default, the latest chart is fetched.
  • fetch – A boolean indicating whether to fetch the chart data from Billboard.com immediately (at instantiation time). If False, the chart data can be populated at a later time using the fetchEntries() method.
  • timeout – The number of seconds to wait for a server response. If None, no timeout is applied.

Walking through chart dates

Every ChartData instance has a previousDate attribute containing a string representation of the previous chart's date. You can feed this into another ChartData instance to effectively walk back through previous charts.

chart = billboard.ChartData('hot-100')
while chart.previousDate:
    doSomething(chart)
    chart = billboard.ChartData('hot-100', chart.previousDate)

Accessing chart entries

If chart is a ChartData instance, we can ask for its entries attribute to get the chart entries (see below) as a list.

For convenience, chart[x] is equivalent to chart.entries[x], and ChartData instances are iterable.

Chart entry attributes

A chart entry (typically a single track) is of type ChartEntry. A ChartEntry instance has the following attributes:

  • title – The title of the track.
  • artist – The name of the artist, as formatted on Billboard.com.
  • peakPos – The track's peak position on the chart at any point in time, including future dates, as an int (or None if the chart does not include this information).
  • lastPos – The track's position on the previous week's chart, as an int (or None if the chart does not include this information). This value is 0 if the track was not on the previous week's chart.
  • weeks – The number of weeks the track has been or was on the chart, including future dates (up until the present time).
  • rank – The track's current position on the chart.
  • isNew – Whether the track is new to the chart.

More resources

For additional documentation, look at the file billboard.py, or use Python's interactive help feature.

Think you found a bug? Create an issue here.

Contributing

Pull requests are welcome! Please adhere to the following style guidelines:

  • In general, follow PEP 8. You may ignore the following rules if following them would decrease readability:
    • E127 ("continuation line over-indented for visual indent")
    • E221 ("multiple spaces before operator")
    • E501 ("line too long")
  • We use mixedCase for variable names.
  • All-uppercase words remain all-uppercase when they appear at the end of variable names (e.g. downloadHTML not downloadHtml).

Running tests

Install tox and nose.

To run all of the tests, run

nosetests

Assuming you have both Python 2.7 and 3.4 installed on your machine, you can also run

tox

to run tests on both versions; see tox.ini for configuration details.

Made with billboard.py

Projects and articles that use billboard.py:

Have an addition? Make a pull request!

Dependencies

License

  • This project is licensed under the MIT License.
  • The Billboard charts are owned by Prometheus Global Media LLC. See Billboard.com's Terms of Use for more information.

billboard-charts's People

Contributors

3ngthrust avatar blha303 avatar brycematsuda avatar danielunderwood avatar emo-eth avatar guoguo12 avatar johannfrias avatar mcookhome avatar schwanksta avatar victorlin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.