Created
July 29, 2016 14:54
-
-
Save riebschlager/9237df6434b30e48bbe5957d2403393f 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 | |
import time | |
import math | |
from datetime import datetime | |
from datetime import timedelta | |
epoch = datetime.utcfromtimestamp(0) | |
def unix_time_millis(dt): | |
return (dt - epoch).total_seconds() * 1000.0 | |
def write_to_csv(url): | |
response = urllib2.urlopen(url) | |
track_list = json.load(response) | |
for song in track_list['events']: | |
if song['title'] != '' and 'KTBG' not in song['artist']: | |
csv_writer.writerow([song['title'].encode('utf-8'), song['artist'].encode('utf-8'), song['album'].encode('utf-8')]) | |
urls = [ | |
'https://ktbg.streamon.fm/eventrange/1469797276-1469800856.json', | |
] | |
csv_file = open('the-bridge.csv', 'wb') | |
csv_writer = csv.writer(csv_file, delimiter='\t') | |
csv_writer.writerow(['Name', 'Artist', 'Album']) | |
now = int(time.time()) | |
then = now - 86000 | |
write_to_csv('https://ktbg.streamon.fm/eventrange/' + str(then) + '-' + str(now)+'.json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment