advenemusic2csv 504 B

12345678910111213141516171819202122
  1. #!/usr/bin/python
  2. import sys
  3. import csv
  4. import json
  5. infname = sys.argv[1]
  6. outfname = sys.argv[2]
  7. j = json.load(open(infname))
  8. w = csv.writer(open(outfname, 'w'), quoting=csv.QUOTE_NONNUMERIC)
  9. w.writerow(('start', 'end', 'artist', 'title', 'background'))
  10. for a in j['annotations']:
  11. w.writerow((
  12. float(a['begin']) / 1000,
  13. float(a['end']) / 1000,
  14. a['parsed']['artist'].encode('utf-8'),
  15. a['parsed']['title'].encode('utf-8'),
  16. a['parsed']['background'],
  17. ))