init
authorDylan Lloyd <dylan@psu.edu>
Thu, 6 Jan 2011 20:41:25 +0000 (15:41 -0500)
committerDylan Lloyd <dylan@psu.edu>
Thu, 6 Jan 2011 20:41:25 +0000 (15:41 -0500)
parse.py [new file with mode: 0644]

diff --git a/parse.py b/parse.py
new file mode 100644 (file)
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 '<a href=\'http://youtube.com/results?search_query=' + urllib.quote_plus(title + ' ' + artists[i]) + '\'>' + title + '</a> by', artists[i], '<br>'
+                i += 1
+        else:
+            print 'parsing error'
+
+def main():
+    stations = fetch_stations(USER)
+    fetch_tracks(stations)
+
+if __name__ ==  "__main__":
+    main()
+