Skip to content

Commit

Permalink
Remove charts() function (the charts/ page no longer shows all charts)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoguo12 committed Nov 20, 2021
1 parent 9d169be commit c123cd9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 52 deletions.
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,11 @@ hot-100 chart from 2018-04-28
Guide
-----

### Listing all charts
### What charts exist?

Use the `charts` function to list all chart names:
[This page](https://www.billboard.com/charts) shows all charts grouped by category.

```Python
>>> billboard.charts()
['hot-100', 'billboard-200', 'artist-100', 'social-50', ...
```

The bottom of [this page](https://www.billboard.com/charts) shows all charts grouped by category.

*Billboard* also publishes [year-end charts](https://en.wikipedia.org/wiki/Billboard_Year-End). List these by passing `year_end=True` to the `charts` function:

```python
>>> billboard.charts(year_end=True)
['top-artists', 'top-artists-duo-group', 'top-artists-female', ...
```

You can also find them [here](https://www.billboard.com/charts/year-end).
Year-end charts are [here](https://www.billboard.com/charts/year-end).

### Downloading a chart

Expand Down
19 changes: 0 additions & 19 deletions billboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,25 +500,6 @@ def fetchEntries(self):
self._parsePage(soup)


def charts(year_end=False):
"""Gets a list of all Billboard charts from Billboard.com.
Args:
year_end: If True, will list Billboard's year-end charts.
"""
session = _get_session_with_retries(max_retries=5)
url = "https://www.billboard.com/charts"
if year_end:
url += "/year-end"
req = session.get(url, timeout=25)
req.raise_for_status()
soup = BeautifulSoup(req.text, "html.parser")
return [
link["href"].split("/")[-1]
for link in soup.findAll("a", {"class": "chart-panel__link"})
]


def _get_session_with_retries(max_retries):
session = requests.Session()
session.mount(
Expand Down
16 changes: 0 additions & 16 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,3 @@ def testDifficultTitleCasing(self):
"""Checks that a difficult chart title receives proper casing."""
chart = billboard.ChartData("greatest-r-b-hip-hop-songs")
self.assertEqual(chart.title, "Greatest of All Time Hot R&B/Hip-Hop Songs")

def testCharts(self):
"""Checks that the function for listing all charts returns reasonable
results."""
charts = billboard.charts()
self.assertTrue("hot-100" in charts)
self.assertTrue(100 <= len(charts) <= 400)

def testChartsYearEnd(self):
"""Checks that the function for listing all year-end charts
returns reasonable results."""
charts = billboard.charts(year_end=True)
chart_names = ["top-artists", "radio-songs", "top-country-albums"]
for name in chart_names:
self.assertTrue(name in charts)
self.assertTrue(300 <= len(charts) <= 500)

0 comments on commit c123cd9

Please sign in to comment.