NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgPort.py
1 """ Module for Porting Tensegrity Data in JSON format (Proof of Concept) """
2 " As an example, this module functions by incrementing the arbitrary field "
3 " 'x' in the provided JSON file "
4 
5 import sys, json
6 from pprint import pprint
7 
8 """ change the state of tensegrity tg """
9 def tweak(tg):
10  tg['x'] += 1
11  pprint(tg)
12  return tg
13 
14 def import_tg_data(filename):
15  tgJSON = open(filename, 'r')
16  tg = json.load(tgJSON)
17  tg_tweaked = tweak(tg)
18  tgJSON.close()
19  return tg_tweaked
20 
21 def export_tg_data(filename, json_data):
22  tgJSON = open('tgData.json', 'w')
23  json.dump(json_data, tgJSON, indent=4)
24  tgJSON.close()
25  return
26 
27 def main(f):
28  tweaked_json_data = import_tg_data(f)
29  export_tg_data(f, tweaked_json_data)
30 
31 if __name__ == '__main__':
32  if (len(sys.argv) > 1):
33  main(sys.argv[1])
34  else:
35  print "Error: no JSON file passed to tgPort.py"