From 476b8628e1965f9714e3d7f4148dfbc3c6f249e9 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Thu, 6 Jan 2011 15:41:25 -0500 Subject: [PATCH 1/1] init --- parse.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 parse.py diff --git a/parse.py b/parse.py new file mode 100644 index 0000000..aa725d3 --- /dev/null +++ b/parse.py @@ -0,0 +1,37 @@ +from BeautifulSoup import BeautifulSoup +import urllib +import re + +USER = 'alphabethos' + +def fetch_stations(user): + tokens = ['0081d3c8e037f4c32a44f01b1701dd31466957fc96e4da2e', 'db592464bbca03e7664b1093336f121ce8c7587b2172781c'] + return tokens + +def fetch_tracks(stations): + for station in stations: + page = urllib.urlopen('http://www.pandora.com/favorites/station_tablerows_thumb_up.vm?token=' + station + '&sort_col=thumbsUpDate') + page = BeautifulSoup(page) + titles = [] + artists = [] + for span in page.findAll('span', attrs={'class':'track_title'}): + for attr, value in span.attrs: + if attr == 'tracktitle': + titles.append(value) + for anchor in page.findAll('a'): + artists.append(anchor.string) + if len(titles) == len(artists): + i = 0 + for title in titles: + print '' + title + ' by', artists[i], '
' + i += 1 + else: + print 'parsing error' + +def main(): + stations = fetch_stations(USER) + fetch_tracks(stations) + +if __name__ == "__main__": + main() + -- 2.30.2