Created
July 29, 2016 13:55
-
-
Save riebschlager/831b914ce53d6f14c20d3cb1945fb9bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import json | |
import csv | |
def write_to_csv(url): | |
response = urllib2.urlopen(url) | |
track_list = json.load(response) | |
for song in track_list: | |
if song['artist'] != '[BREAK]': | |
csv_writer.writerow([song['title'], song['artist']]) | |
urls = [ | |
'http://tracklist-api.kcrw.com/Simulcast/date/2016/07/25?time=00:00', | |
'http://tracklist-api.kcrw.com/Simulcast/date/2016/07/24?time=00:00', | |
'http://tracklist-api.kcrw.com/Simulcast/date/2016/07/23?time=00:00', | |
'http://tracklist-api.kcrw.com/Simulcast/date/2016/07/22?time=00:00', | |
] | |
csv_file = open('track-list.csv', 'wb') | |
csv_writer = csv.writer(csv_file) | |
csv_writer.writerow(['Name', 'Artist']) | |
for url in urls: | |
print "Fetching: " + url | |
write_to_csv(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment