Skip to content

Instantly share code, notes, and snippets.

@riebschlager
Created July 29, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riebschlager/9237df6434b30e48bbe5957d2403393f to your computer and use it in GitHub Desktop.
Save riebschlager/9237df6434b30e48bbe5957d2403393f to your computer and use it in GitHub Desktop.
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