source: other-projects/mirex/grand-challenge/generate-jamendo-dataset/scripts-2015/gather-together-evened-out-json.py@ 30010

Last change on this file since 30010 was 30010, checked in by davidb, 9 years ago

Script to pull together the individual JSON files into one single one

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1#!/usr/bin/python
2
3import os
4import os.path
5
6import json
7import sys
8
9argc = len(sys.argv)
10
11json_input_file = sys.argv[1] if (argc>=2) and (argc<=4) else 'jamendo-evened-out-10000-dataset-trackids.json'
12input_dir = sys.argv[2] if (argc==3) or (argc==4) else 'download-json-evened-out'
13output_file = sys.argv[3] if argc==4 else "jamendo-evened-out-10000-dataset-info.json"
14
15
16evened_out_json_data=open(json_input_file).read()
17evened_out_jamendo_ids=json.loads(evened_out_json_data)
18
19#json_files = [ jf for jf in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir,jf)) ]
20
21json_dataset = []
22
23for jid in evened_out_jamendo_ids:
24#for jf in json_files:
25 json_filename = os.path.join(input_dir,jid + ".json")
26 json_data=open(json_filename).read()
27 data = json.loads(json_data)
28
29 for rec in data[u'results']:
30 print "Adding track id: " + rec[u"id"]
31 json_dataset.append(rec)
32
33print "Writing out JSON file ..."
34with open(output_file, "w") as json_ofile:
35 json.dump(json_dataset,json_ofile)
36print "Done"
37
Note: See TracBrowser for help on using the repository browser.