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
|
Rev | Line | |
---|
[30010] | 1 | #!/usr/bin/python
|
---|
| 2 |
|
---|
| 3 | import os
|
---|
| 4 | import os.path
|
---|
| 5 |
|
---|
| 6 | import json
|
---|
| 7 | import sys
|
---|
| 8 |
|
---|
| 9 | argc = len(sys.argv)
|
---|
| 10 |
|
---|
| 11 | json_input_file = sys.argv[1] if (argc>=2) and (argc<=4) else 'jamendo-evened-out-10000-dataset-trackids.json'
|
---|
| 12 | input_dir = sys.argv[2] if (argc==3) or (argc==4) else 'download-json-evened-out'
|
---|
| 13 | output_file = sys.argv[3] if argc==4 else "jamendo-evened-out-10000-dataset-info.json"
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | evened_out_json_data=open(json_input_file).read()
|
---|
| 17 | evened_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 |
|
---|
| 21 | json_dataset = []
|
---|
| 22 |
|
---|
| 23 | for 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 |
|
---|
| 33 | print "Writing out JSON file ..."
|
---|
| 34 | with open(output_file, "w") as json_ofile:
|
---|
| 35 | json.dump(json_dataset,json_ofile)
|
---|
| 36 | print "Done"
|
---|
| 37 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.