Git Product home page Git Product logo

billboard-charts's Introduction

billboard.py

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

Installation

Install with pip:

pip install billboard.py

Or clone this repo 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')
>>> chart.title
'The 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

What charts exist?

This page shows all charts grouped by category.

Year-end charts are here.

Downloading a chart

Use the ChartData constructor to download a chart:

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

The arguments are:

  • name – The chart name, e.g. 'hot-100' or 'pop-songs'.
  • date – The chart date as a string, in YYYY-MM-DD format. By default, the latest chart is fetched.
  • year – The chart year, if requesting a year-end chart. Must be a string in YYYY format. Cannot supply both date and year.
  • 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.
  • max_retries – The max number of times to retry when requesting data (default: 5).
  • timeout – The number of seconds to wait for a server response. If None, no timeout is applied.

For example, to download the Alternative Songs year-end chart for 2006:

>>> chart = billboard.ChartData('alternative-songs', year=2006)

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.
  • image – The URL of the image for the track.
  • peakPos – The track's peak position on the chart as of the chart date, 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:

  • We use Black for formatting.
    • If you have pre-commit installed, run pre-commit install to install a pre-commit hook that runs Black.
  • Variable names should be in mixedCase.

Running tests

To run the test suite locally, install nose and run

nosetests

To run the test suite locally on both Python 2.7 and 3.4, install tox and run

tox

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 aag avatar blha303 avatar brycematsuda avatar cameronezell avatar danielunderwood avatar emo-eth avatar guoguo12 avatar johannfrias avatar johnwmillr avatar mcookhome avatar schwanksta avatar victorlin avatar vitalii-chartmetric avatar yajanarao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

billboard-charts's Issues

Api problems

You have the same issue as #74.
Please, update the library to the version 6.1.2.

I did update it to 6.1.2. prior to my message and it doesnt work.Do I have to change sth more?

Problem when going backwards in time

I want to get all billboard charts up to a certain date.

My code looks like this:

    chart = billboard.ChartData('hot-100')
    year = int(chart.date[:4])

    while year >= 1995:
        print(year)
        print(chart.date)

        # Get older chart
        chart = billboard.ChartData('hot-100', date=chart.previousDate)
        year = int(chart.date[:4])

Sadly i get an output like this:
...
2014
2014-03-15
2014
2014-03-08
2017
2017-12-09
2017
2017-12-02
...

or
...
2013
2013-10-12
2013
2013-10-05
2017
2017-12-09
...

-> It switches back to the latest one but the exact date of chart where this happens differs.
Any idea on how i could fix this?

Add download timeout

From the Requests documentation:

You can tell Requests to stop waiting for a response after a given number of seconds with the timeout parameter. Nearly all production code should use this parameter in nearly all requests. Failure to do so can cause your program to hang indefinitely.

This caused a lot of pain at #25, so we should fix this ASAP.

Fetching wrong dates sometimes doesn't round, sometimes it does.

quote from comment on Billboard.py" date: The chart date, as a string in YYYY-MM-DD format.
By default, the latest chart is fetched.
>>>If the argument is not a date on which a chart was published,
>>>Billboard automatically rounds dates up to the nearest date on
>>>which a chart was published."
This behavior doesn't happen, dont know if it ever did cause i just started using it, but trying to use a few dates like 2017-12-12 or 2017-12-19 end on no results, billboard site doesn't change to the nearest result if the date input is done through the address don't know if they changed the behavior on that, this happens only if the wrong date is put on the site's search field, then it moves to the next available chart.

Lyrics in search results?

Is there a way to include lyrics in the search results? <a class="chart-element__information__lyrics show-more__hidden-el" title="Read Lyrics of Blinding Lights by The Weeknd" href="https://www.billboard.com/articles/news/lyrics/8545919/the-weeknd-blinding-lights-lyrics" target="_blank">Song Lyrics</a> I guess that the following is the html element containing the address for the lyrics. Would I add "chart-element_information_lyrics show-more_hidden-el" to the css selector?

API suddenly not work!

Hello! I'm using billboard-charts API every week.
Yesterday I heard billboard updated new chart 'global 200 chart', so I try to check it.
But when I call the chart for example billboard.ChartData('hot-100), then error occured.

KeyError: 'data-previous-chart-date'

Anyone can solve this problem?
Thank u

error retrieving chart "greatest-hot-100-singles" "greatest-country-songs" etc

Here's the trace log:

chart = billboard.ChartData('greatest-hot-100-singles') File "C:\Users\username\PycharmProjects\project\env\lib\site-packages\billboard.py", line 116, in __init__ self.fetchEntries(all=all) File "C:\Users\username\PycharmProjects\project\env\lib\site-packages\billboard.py", line 211, in fetchEntries peakPos = int(getRowValue('top-spot')) File "C:\Users\username\PycharmProjects\project\env\lib\site-packages\billboard.py", line 207, in getRowValue return entrySoup.select_one(selector).string.strip()
AttributeError: 'NoneType' object has no attribute 'string'

please add support for billboard.com/chart/artist-100

currently 'artist-100' chart isn't supported, kindly add support

chart = billboard.ChartData('artist-100')
File "C:\Users\username\PycharmProjects\project\env\lib\site-packages\billboard.py", line 116, in __init__
self.fetchEntries(all=all)
File "C:\Users\username\PycharmProjects\project\env\lib\site-packages\billboard.py", line 200, in fetchEntries
if (basicInfoSoup[3].find('a')):

IndexError: list index out of range

Improve documentation generation

Currently, the documentation in the readme needs to be updated manually every time a docstring changes. This is bad. For consistency and convenience, we should generate the documentation page directly from the source using pydoc.

The documentation also belongs on its own page. It shouldn't be crammed into the readme.

still broken

is billboard.py broken?

nothing works from my endpoint, not a single call.

problem

I have a problem using this script:

$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import billboard
chart = billboard.ChartData('hot-100')
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/billboard.py", line 104, in init
self.fetchEntries(all=all)
File "/Library/Python/2.7/site-packages/billboard.py", line 155, in fetchEntries
basicInfoSoup = entry_soup.find('div', 'row-title').contents
AttributeError: 'NoneType' object has no attribute 'contents'

I don't know what is the problem. Help please.

Thanks in advance.

403 Client Error: Forbidden for url

A 403 Client Error: Forbidden for url is thrown in billboard.py.

Error occurs at self.fetchEntries() at line 152.

Error occurs at line 199 inside the fetchEntries function.

line 199: req = requests.get(url, timeout=self._timeout)

This error most likely occurs because billboard added some kind of new scraping safeguard.

The way I got around this was by changing the Headers User Agent to this:

'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36'

It's the latest User Agent for Chrome. It should solve any problems having to do with a 403 Client Error: Forbidden for url.

#1 entry is duplicated

I think Billboard changed their UI. The top entry (on any chart) is now shown twice: once in the top banner and once in the table below. As a result, a majority of the unit tests are failing (log).

Billboard 200 not returning any charts prior to 11/18/1989

Hi all, when running the below code to try and print the Billboard 200 on any chart on or before 11/18/1989, I get this message:

import billboard
def chart_to_dict(chart):
    output = []
    for entry in chart.entries:
        row = {'title':entry.title,
               'artist':entry.artist,
               'rank':entry.rank}
        output.append(row)
    return output

class ChartArchive:
    def __init__(self, chart_name):
        self.chart_name = chart_name
        self.charts = []
    def one_off(self, dates):
        for date in dates:
            chart = billboard.ChartData(self.chart_name, date)
            d = {'date': chart.date, 'chart': chart_to_dict(chart)}
            self.charts.append(d)

one_off_date = ['1989-11-18']
one_off_name = 'billboard-200'
one_off_chart = ChartArchive(one_off_name)
one_off_chart.one_off(one_off_date)
one_off_chart.charts

AttributeError                            Traceback (most recent call last)
~\Anaconda3\lib\site-packages\billboard.py in _parseNewStylePage(self, soup)
    290             try:
--> 291                 artist = getEntryAttr("span.chart-element__information__artist") or ""
    292             except:

~\Anaconda3\lib\site-packages\billboard.py in getEntryAttr(selector)
    281             def getEntryAttr(selector):
--> 282                 return entrySoup.select_one(selector).text.strip()
    283 

AttributeError: 'NoneType' object has no attribute 'text'

During handling of the above exception, another exception occurred:

BillboardParseException                   Traceback (most recent call last)
<ipython-input-9-38c654d4ba80> in <module>
     23 one_off_name = 'billboard-200'
     24 one_off_chart = ChartArchive(one_off_name)
---> 25 one_off_chart.one_off(one_off_date)
     26 one_off_chart.charts

<ipython-input-9-38c654d4ba80> in one_off(self, dates)
     16     def one_off(self, dates):
     17         for date in dates:
---> 18             chart = billboard.ChartData(self.chart_name, date)
     19             d = {'date': chart.date, 'chart': chart_to_dict(chart)}
     20             self.charts.append(d)

~\Anaconda3\lib\site-packages\billboard.py in __init__(self, name, date, fetch, max_retries, timeout)
    150         self.entries = []
    151         if fetch:
--> 152             self.fetchEntries()
    153 
    154     def __repr__(self):

~\Anaconda3\lib\site-packages\billboard.py in fetchEntries(self)
    369 
    370         soup = BeautifulSoup(req.text, "html.parser")
--> 371         self._parsePage(soup)
    372 
    373 

~\Anaconda3\lib\site-packages\billboard.py in _parsePage(self, soup)
    349             self._parseOldStylePage(soup)
    350         else:
--> 351             self._parseNewStylePage(soup)
    352 
    353     def fetchEntries(self):

~\Anaconda3\lib\site-packages\billboard.py in _parseNewStylePage(self, soup)
    292             except:
    293                 message = "Failed to parse artist"
--> 294                 raise BillboardParseException(message)
    295 
    296             if artist == "":

BillboardParseException: Failed to parse artist

To confirm, the code above executes successfully when given the date 11/25/1989. Has anyone encountered this? Feedback is appreciated.

Produces a 67 second delay every 24 requests.

I'm pulling every hot 100 chart into JSON format. I have set the scraper to have a timeout of 4 seconds and a max-retries of 1, but somehow it still produces a 67 second delay once every 24 requests. This adds a significant amount of time to my aggregator's runtime.

This API NOT WORK NOW!

This API not work now.
I think it;s because of billboard chart web site update.
Can you please check this issue?

unable to get image of track

I am unable to get the image of the track. for example

>>> sample=billboard.ChartData('hot-100')
>>> sample[0].image
None

How to fix this?

Latest commits

Billboard changed their website, so spotifyLink was broken. I fixed that, and added an additional spotifyID field. I figure that's probably more useful for the Spotify/Echo Nest APIs, since you can forgo string manipulations. I kept the same format for spotifyLink (which uses the embed.spotify URL, rather than open.spotify) since I wasn't sure if there were any dependencies on it using embed.spotify.
I also cleaned up the .to_JSON() methods since a few lines in the ChartData class were redundant.
I tentatively bumped the version to 2.0.1. I'm sure how to go about getting that on PyPi.
A while back I also built a BillboardIter class, which iterates over valid Billboard dates. Would anyone else find that useful? I don't think my repo listed on my github is up to date, though. Can push if there's interest.

Let me know if you think this will bring about any problems or what I can do in the future.

Additional unit tests needed

As mentioned in #35, we need:

  • A test for album charts, e.g., this chart. This test should look similar to test_hot_100.py.
  • A test for when a non-existent chart name is used: billboard.ChartData('nonsense'). (Before writing a test, we need to specify what ought to happen here. I suggest we raise an exception.)
  • We need more tests involving date edge cases (earliest chart, most recent chart, etc.).

Specify a year

Hi,
I have this code bellow which shows the billboard for the pop songs:

from billboard import charts
from billboard import ChartData
from pprint import pprint

chart = ChartData('pop-songs')

Is it possible to specify a year for instance: pop-songs of 2019
image

And also how can i get the hot-100 of a specific decade-end?

SpotifyID populated when page shows no active link

Came across this problem when trying to create a unique song ID for tracks. Essentially, some tracks are assigned a SpotifyID that does not necessarily refer to that track. Here's an example:
"Mine" by Beyonce featuring Drake has no active "Listen on Spotify" link: http://www.billboard.com/charts/hot-100/2014-01-11 but the HTML stores an ID anyways:

<article class="chart-row row-new chart-row--99 js-chart-row" data-hovertracklabel="Song Hover-Mine" data-songtitle="" data-spotifyType="track" data-spotifyUri="track:0dBW6ZsW8skfvoRfgeerBF" data-spotifyId="0dBW6ZsW8skfvoRfgeerBF">

This particular ID corresponds to Mine by Taylor Swift - clearly an issue stemming from Billboard itself. Not sure if there is a way to control for this in the billboard.py script.

Incorrect values for songs debuting at number 1

From line 246 in billboard.py:

# if there is no div with class div.chart-number-one__last-week, that means it was the top song the prior week

This is incorrectly returning False for isNew and 1 for lastPos on songs debuting at number 1.

Songs debuting at number 1 have a star shaped badge that say 'NEW' with a CSS selector img.chart-number-one__stats-cell-new. Perhaps, check for this in the absence of div.chart-number-one__last-week before assigning those values?

Throw exceptions for scraping errors

As suggested in #15, we should catch errors during the scraping process and wrap them in a new kind of exception. We can use the "spotify-rewind" playlist as a test.

Use __str__ for pretty-printing entries, and __repr__ for object representation

Documentation for __repr__:

this function makes an attempt to return a string that would yield an object with the same value when passed to eval()

Documentation for __str__:

Return a string containing a nicely printable representation of an object.

Currently, calling str() or print on a ChartData invokes __repr__ since __str__ is not implemented.

Instead, __repr__ could return a representation of the chart object (with corrected dates), and the current code can be used for __str__. Maybe the following the behavior:

> chart = billboard.ChartData('hot-100', date='1996-07-30')
> print repr(chart)
billboard.ChartData('hot-100', date='1996-08-03')
> print chart
hot-100 chart from 1996-08-03
-----------------------------
1. ‘Macarena (Bayside Boys Mix)’ by Los Del Rio
...

Should be an easy fix. Let me know if this is a good idea, and I can go ahead and implement it.

Empty chart data

In trying to access any chart (I've tried hot-100 and pop-songs) for any date (current, or dates in the past), the result is always an empty chart. Do you know what could be causing this? I've used this library in the past successfully, so I'm not sure why the same code doesn't seem to be returning anything.

Here's an example of what I'm running

chart = billboard.ChartData('pop-songs', date='2015-11-28')
print chart

and the response

pop-songs chart from 2015-11-28
-------------------------------

Cannot fetch the Hot 100 chart

As of today this simple code started to give me an error:

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

This is the Trace:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/marco97pa/.pyenv/versions/3.9.3/lib/python3.9/site-packages/billboard.py", line 190, in __init__
    self.fetchEntries()
  File "/home/marco97pa/.pyenv/versions/3.9.3/lib/python3.9/site-packages/billboard.py", line 487, in fetchEntries
    self._parsePage(soup)
  File "/home/marco97pa/.pyenv/versions/3.9.3/lib/python3.9/site-packages/billboard.py", line 461, in _parsePage
    self._parseNewStylePage(soup)
  File "/home/marco97pa/.pyenv/versions/3.9.3/lib/python3.9/site-packages/billboard.py", line 319, in _parseNewStylePage
    self.previousDate = soup.select_one("#charts")["data-chart-prev-date"]
TypeError: 'NoneType' object is not subscriptable

I run this code everyday and yesterday it was working. Maybe there was a change on structure of the website of the chart?

Can't get Chart printed. & Index error when try to Get song on chart by index

  1. Tried running below code and print(chart) gave me nothing but Header "hot-100 chart (current)"
  2. printing Song by fetching chart[0] gave me index issue.

import billboard
chart = billboard.ChartData('hot-100')
print(chart)
song = chart[0]
print(song)

*************Console output
Traceback (most recent call last):
hot-100 chart (current)

File "C:/Users/manish/PycharmProjects/SongCollector/POCtest/bilboardLis.py", line 4, in
song = chart[0]
File "C:\Users\manish\PycharmProjects\SongCollector\venv\lib\site-packages\billboard.py", line 175, in getitem
return self.entries[key]
IndexError: list index out of range

Process finished with exit code 1

Unable to perform example query

Hey!

As far as I'm aware, despite successfully cloning/setup-ing, the sample case

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

consistently returns a nasty

TypeError: 'NoneType' object is not callable

after that last line. Below is the full error trace generated after running:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-bd1122414877> in <module>()
----> 1 chart = billboard.ChartData('hot-100')

/Users/dannyvilela/Desktop/GitHub/billboard-charts/billboard.py in __init__(self, name, date, fetch, all)
    100         self.entries = []
    101         if fetch:
--> 102             self.fetchEntries(all=all)
    103 
    104     def __repr__(self):

/Users/dannyvilela/Desktop/GitHub/billboard-charts/billboard.py in fetchEntries(self, all)
    176             # Grab week data (peak rank, last week's rank, total weeks on
    177             # chart)
--> 178             peakPos = int(getRowValue('top-spot'))
    179 
    180             lastPos = getRowValue('last-week')

/Users/dannyvilela/Desktop/GitHub/billboard-charts/billboard.py in getRowValue(rowName)
    172             def getRowValue(rowName):
    173                 selector = 'div.chart-row__' + rowName + ' .chart-row__value'
--> 174                 return entry_soup.select_one(selector).string.strip()
    175 
    176             # Grab week data (peak rank, last week's rank, total weeks on

TypeError: 'NoneType' object is not callable

Would there happen to be a simple workaround for this particular issue? Thanks for the help!

Chart Data Error

I've been using this code with no issues until recently. When I run the ChartData function I get the error below:

`import pandas as pd
import numpy as np
import billboard
import time
import datetime

today = datetime.datetime.now()

artists = []
songs = []
dates = []
positions = []
chart = billboard.ChartData('billboard-200')
KeyError: 'data-previous-chart-date'`

Even when I include a date, the same error occurs:

>>> chart = billboard.ChartData('billboard-200','2019-01-07') KeyError: 'data-previous-chart-date'

`

SpotifyIDs for version 3.0.2

So I am trying to get the spotify IDs of the billboard songs, and it looks like version 3.0.2 had a 'spotifyID' attribute for every song instance in the billboard chart instance. Is it possible to get that again? Also, the spotify IDs are unavailable for almost all the songs I searched for. It would help me a lot if getting the spotify IDs is possible again.

[urgent] Am I mistaken or is this broken right now?

I have tried to retrieve a chart on two separate machines, and have been unable to get any tracks:

broken billboard

Am I calling it wrong @guoguo12?

I notice that Billboard's website's UI has changed, and fairly drastically so. I imagine that could have easily messed up the fairly advanced scraping you're doing.

If there's any more context I could give to help, please let me know.

Meaning of peakPos

A minor thing, but I think the description of peakPos on the README is confusing and perhaps incorrect. It is described as "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)." I think it is the peak position as of the week the chart was published. Otherwise pulling a past chart would show a higher peak position when the track first enters the chart. Maybe it should be "highest position track has reached as of chart date".

date title artist current previous peak weeks
2013-02-23 Started From The Bottom Drake 63 0 63 1
2013-03-02 Started From The Bottom Drake 10 63 10 2
2013-03-09 Started From The Bottom Drake 6 10 6 3
2013-03-16 Started From The Bottom Drake 6 6 6 4
2013-03-23 Started From The Bottom Drake 7 6 6 5
2013-03-30 Started From The Bottom Drake 6 7 6 6
2013-04-06 Started From The Bottom Drake 7 6 6 7
2013-04-13 Started From The Bottom Drake 8 7 6 8
2013-04-20 Started From The Bottom Drake 9 8 6 9
2013-04-27 Started From The Bottom Drake 9 9 6 10

Inconsistency in weeks values

Looking trough data scraped from 2018, I am getting 604 entries at 0 weeks on the chart, 4 at 1 week, and 393 at 2 weeks.
Incidentally, the 4 entries at week 1 are the four songs that debuted at number 1 in 2018 on their debut weeks, which could be connected to issue #49 :

                          title  weeks
date       rank                                
2018-11-17 1       Thank U, Next      1
2018-05-19 1     This Is America      1
2018-04-21 1       Nice For What      1
2018-02-03 1          God's Plan      1

I think the discrepancy is because you are assigning the first week on the chart to 0 at line 286 in Billboard.py when getPositionRowValue(rowName) is passed _WEEKS_ON_CHART_FORMAT, but Billboard starts counting weeks at 1, which you can see for This Is America on it's debut week, but is not included for songs debuting at lower ranks, as is shown for Watch's number 16 debut that same week.

Timeout on older charts

This error indicates it is more a problem from Billboard, but in a loop pulling charts I get significantly more timeouts on older charts, starting seriously around 2010. These aren't rate-limiting issues as I've mitigated those with time intervals and the error is different ... it seems like Billboard won't respond quickly enough. Sometimes it will grab two or three charts and then die. I can use the same code to pull recent charts with no problem, but once I try for an older year, it times out again.

Here is an example

Not sure your module can do anything about this ... more wondering if other folks have seen this.

'spotify-rewind' chart does not work

thx for the nice work btw
I'm using python3.6 and
billboard.py==3.0.2
Maybe formatting is unconventional / not what you were expecting, looking at
http://www.billboard.com/charts/spotify-rewind

In [1]: import billboard

In [2]: ch = billboard.ChartData('spotify-rewind')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-7e40362569e4> in <module>()
----> 1 ch = billboard.ChartData('spotify-rewind')

/home/chris/anaconda3/lib/python3.6/site-packages/billboard.py in __init__(self, name, date, fetch, all, quantize)
    114         self.entries = []
    115         if fetch:
--> 116             self.fetchEntries(all=all)
    117 
    118     def __repr__(self):

/home/chris/anaconda3/lib/python3.6/site-packages/billboard.py in fetchEntries(self, all)
    209             # Grab week data (peak rank, last week's rank, total weeks on
    210             # chart)
--> 211             peakPos = int(getRowValue('top-spot'))
    212 
    213             lastPos = getRowValue('last-week')

/home/chris/anaconda3/lib/python3.6/site-packages/billboard.py in getRowValue(rowName)
    205             def getRowValue(rowName):
    206                 selector = 'div.chart-row__' + rowName + ' .chart-row__value'
--> 207                 return entrySoup.select_one(selector).string.strip()
    208 
    209             # Grab week data (peak rank, last week's rank, total weeks on

AttributeError: 'NoneType' object has no attribute 'string'

Charts relying on "old style" parsing missing previousDate & nextDate at extremes

Hi Allen,

I believe I found a bug relating to the previousDate and nextDate values of ChartData for charts that rely on the old-style page parsing.

When an old-style chart parses either its oldest or newest page, the previousDate and nextDate values (respectively) will be missing from the ChartData object, rather than being set to '' or None.

Missing previousDate

chart = billboard.ChartData("country-songs", date="1958-10-20")
chart.previousDate

AttributeError Traceback (most recent call last)
<ipython-input-52-b3eed127b189> in <module>
----> 1 chart.previousDate

AttributeError: 'ChartData' object has no attribute 'previousDate'

Missing nextDate

chart = billboard.ChartData("country-streaming-songs", date="2020-10-31")
chart.nextDate

AttributeError Traceback (most recent call last)
<ipython-input-56-3564beeeeb8c> in <module>
----> 1 chart.nextDate

AttributeError: 'ChartData' object has no attribute 'nextDate'

Correctly function new-style chart

chart = billboard.ChartData("hot-100", date="1958-08-04")
chart.previousDate

''

I can put together a PR for this in the next couple of days. It should be a fairly straightforward fix.

chartInfoSoup contents - album info index off by one

First off, thanks so much for doing this. As both a charts geek and CS major, I've always wanted to implement the Hot 100 into a simpler, quick and easy to read layout. I was disappointed to learn that the Billboard API had been shut down for awhile now...and then I found this a few days ago and was immediately overjoyed.

Anyway, some background on the issue, I've implemented the basic API functionality into a personal project web app of mine (which can be found here) where right now it displays the top 10 entries info and all that. I also put the info in a SQLite database so the app doesn't have to spend time re-downloading the same info over and over again when navigating to the page.

bild3billboard

A couple of hours ago though, while making some adjustments, all the albums for every entry suddenly became null and the compiler obviously wasn't happy about it. I thought it had something to do with my program, but just to check, I ran another unaltered copy of the API script in a separate folder, and all of the albums turned up null as well.

albumnone

I had the feeling that the pages code had changed somehow and now the script was grabbing the wrong thing, so I printed out the contents of chartInfoSoup and here's what I got.

billboardsoupcontents

If you count the indexes, you can see the album info got pushed one over by the <br> tag. I shifted the index the album string gets its info from 3 to 4 so lines 77-80 look like this:

if chartInfoSoup.contents[4].string:
    album = chartInfoSoup.contents[4].string.strip()
else:
    album = None

And it seemed to grab the album info like normally again. I'm not putting a PR for now....since I'm kinda skeptical that it will stay this way, but if it stays the same after a few days then I'll likely do so. Just keeping it as an issue as maybe something to monitor.

Spotify ID is gone

I had a script that parsed info from Billboard as well and for what I see the Spotify ID for each song is gone.

Issue with old style?

Hi folks,

I'm not even sure how to explain this one myself.
For me, billboard works perfectly, but when bundled as part of a package, a couple of users report errors when opening charts. From the error report I receive this traceback:
"billboard.py", line 190, in init
File "billboard.py", line 487, in fetchEntries
File "billboard.py", line 459, in _parsePage
File "billboard.py", line 236, in _parseOldStylePage
File "_strptime.py", line 568, in _strptime_datetime
File "_strptime.py", line 349, in _strptime
ValueError: time data 'April 10, 2021' does not match format '%B %d, %Y'"

When, it quite obviously does?
Should I just force old_style to go through new_style? Any ideas here would be appreciated as I'm at the point where i'm wondering if python has been having some of the good stuff behind my back!

Python version 3.8.6,

image url not working?

Every time I try to use

song = chart[0] print(song.image)

It keeps returning None (for all songs). Is there any reason for this?

Support for year-end charts

Year-end charts does not seem to be supported at the moment.

It would be great if the library can use https://www.billboard.com/charts/year-end/YEAR/CHARTNAME in addition to https://www.billboard.com/charts/CHARTNAME

API doesnt work

This still doesnt work, even after installing new version

Hello! I'm using billboard-charts API every week.
Yesterday I heard billboard updated new chart 'global 200 chart', so I try to check it.
But when I call the chart for example billboard.ChartData('hot-100), then error occured.

KeyError: 'data-previous-chart-date'

Anyone can solve this problem?
Thank u

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.