b5032b3f014517acc881a9af99949c1347f53c03
1 __author__
= ("Dylan Lloyd <dylan@psu.edu>")
10 from BeautifulSoup
import BeautifulSoup
12 def fetch_stations(user
):
14 page
= urllib
.urlopen('http://www.pandora.com/favorites/profile_tablerows_station.vm?webname=' + USER
)
15 page
= BeautifulSoup(page
)
16 table
= page
.findAll('div', attrs
={'class':'station_table_row'})
19 for attr
, value
in row
.find('a').attrs
:
21 stations
.append(value
[10:])
24 def fetch_tracks(stations
):
25 for station
in stations
:
26 page
= urllib
.urlopen('http://www.pandora.com/favorites/station_tablerows_thumb_up.vm?token=' + station
+ '&sort_col=thumbsUpDate')
27 page
= BeautifulSoup(page
)
30 for span
in page
.findAll('span', attrs
={'class':'track_title'}):
31 for attr
, value
in span
.attrs
:
32 if attr
== 'tracktitle':
34 for anchor
in page
.findAll('a'):
35 artists
.append(anchor
.string
)
36 if len(titles
) == len(artists
):
39 print '<a href=\'http://youtube.com/results?search_query=' + urllib
.quote_plus(title
+ ' ' + artists
[i
]) + '\'>' + title
+ '</a> by', artists
[i
], '<br>'
45 stations
= fetch_stations(USER
)
46 fetch_tracks(stations
)
48 if __name__
== "__main__":