annotate jsonParse.py @ 3:ac421dc9bda8 draft default tip

Uploaded
author ntino
date Mon, 06 May 2019 20:20:59 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
1 #!/usr/bin/env python
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
2
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
3
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
4 import json, sys
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
5
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
6 with open(sys.argv[1]) as file:
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
7 data = json.load(file)
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
8 tool = {}
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
9 for i in range(len(data['steps'].keys())):
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
10 tool[i] = {}
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
11
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
12 print data['steps'][str(i)]['id']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
13 tool[i]['step_number'] = data['steps'][str(i)]['id']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
14 print data['steps'][str(i)]['name']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
15 tool[i]['name'] = data['steps'][str(i)]['name']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
16 print data['steps'][str(i)]['tool_version']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
17 tool[i]['tool_version'] = data['steps'][str(i)]['tool_version']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
18 print data['steps'][str(i)]['tool_id']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
19 tool[i]['tool_id'] = data['steps'][str(i)]['tool_id']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
20 tool[i]['input_list'] = []
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
21 for step in data['steps'][str(i)]['inputs']:
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
22 print step['name'], step['description']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
23 a = {'name': step['name'], 'description': step['description']}
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
24 tool[i]['input_list'].append(a)
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
25 print ''
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
26 tool[i]['output_list'] = []
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
27 for step in data['steps'][str(i)]['outputs']:
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
28 print step['name'], step['type']
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
29 a = {'name': str(step['name']+'.'+step['type']), 'type': step['type']}
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
30 # tool[i]['output_list']['address'] =
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
31 tool[i]['output_list'].append(a)
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
32 print '\n'
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
33 json_data = json.dumps(tool)
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
34
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
35 for i in tool:
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
36 print json.dumps(tool[i])
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
37
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
38 print type(tool.keys())
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
39
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
40 with open(sys.argv[2], 'w') as file:
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
41 file.write('[')
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
42 for i in tool.keys():
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
43 file.write(json.dumps(tool[i], sort_keys=True, indent=4))
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
44 if i == tool.keys()[-1]: continue
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
45 else: file.write(',')
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
46 file.write(']')
ac421dc9bda8 Uploaded
ntino
parents:
diff changeset
47