Skip to content

Instantly share code, notes, and snippets.

@riebschlager
Created July 29, 2016 13:55
Show Gist options
  • Save riebschlager/831b914ce53d6f14c20d3cb1945fb9bb to your computer and use it in GitHub Desktop.
Save riebschlager/831b914ce53d6f14c20d3cb1945fb9bb to your computer and use it in GitHub Desktop.
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