Last active 1440822152

Returns a list of tuples for each item in a specified Billboard Top 100 list. Planning a Arch Rollback Machine-style repository for popular music

Steven Smith revised this gist 1433491904. Go to revision

1 file changed, 26 insertions

get-billboard.py(file created)

@@ -0,0 +1,26 @@
1 + #!/usr/bin/env python2
2 + from bs4 import BeautifulSoup as Soup
3 + import requests
4 + from collections import namedtuple
5 + from datetime import datetime, timedelta
6 +
7 + Song = namedtuple('Song', ['title', 'artist', 'position', 'spotify', 'vevo', 'rdio'])
8 +
9 + def billboard(date):
10 + soup = Soup(requests.get("http://www.billboard.com/charts/hot-100/%s" % date).text)
11 + songs = soup.findAll('article', {'class': 'chart-row'})
12 + for item in songs:
13 + title = item.find('h2').text.strip()
14 + artist = item.find('h3').text.strip()
15 + position = item.find('span', {'class': 'this-week'}).text.strip()
16 + _ = item.find('a', {'class': 'spotify'})
17 + spotify = _["href"].split("uri=")[1] if _ else None
18 + _ = item.find('a', {'title': 'Vevo'})
19 + vevo = _["href"].split("video=")[1] if _ else None
20 + _ = item.find('a', {'class': 'rdio'})
21 + rdio = _['href'] if _ else None
22 + yield Song(title, artist, position, spotify, vevo, rdio)
23 +
24 + if __name__ == "__main__":
25 + for song in billboard('2015-06-06'):
26 + print song
Newer Older