#!/usr/bin/env python
from __future__ import print_function
import sys

from  eTraveler.clientAPI.connection import Connection


myConn = Connection('jrb', 'Dev', localServer=False)
#myConn = Connection('jrb', 'Dev', localServer=True, debug=True)
#myConn = Connection('jrb', 'Raw', prodServer=True)
rsp = {}
try:
    run = '4689D'
    step = 'read_noise_raft'
    rsp = myConn.getRunResults(run=run, stepName=step, itemFilter=('amp', 3))
    for k in rsp:
        if k != 'steps':
            print('Value for key ',k, ' is ',rsp[k])
    steps = rsp['steps']
    for s in steps:
        print('For stepName %s \n' % (s) )
        sv = steps[s]
        for schname in sv:
            print('\n\nGot data for schema %s' % (schname))
            instances = sv[schname]
            print('Instance 0: ')
            for field in instances[0]:
                print(field, ':', instances[0][field])
            if len(instances) > 1:
                print('\nInstance 1: ')
                for field in instances[1]:
                    print(field, ':', instances[1][field])
    sys.exit(0)
except Exception as msg:
    print('Operation failed with exception: ')
    print(msg)
    sys.exit(1)

