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

Revision 0b7969f36c0ee3a20de31c980b79e4ded91aed65

get-billboard.py Raw
1#!/usr/bin/env python2
2from bs4 import BeautifulSoup as Soup
3import requests
4from collections import namedtuple
5from datetime import datetime, timedelta
6
7Song = namedtuple('Song', ['title', 'artist', 'position', 'spotify', 'vevo', 'rdio'])
8
9def 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
24if __name__ == "__main__":
25 for song in billboard('2015-06-06'):
26 print song