cs-import



In [ ]:
from bayeos.frame.cli import FrameClient
import datetime

In [ ]:
# Data source
host = "132.180.116.106"
table = "avg_top"

In [ ]:
# Mapping
mapping = [['Ts_top_Avg',200394],['dH2O_C_Avg',200395]]

In [ ]:
# Destination
folderId = 200389
alias = 'root@bayconf'

In [ ]:
# Slice
cols = [x[0] for x in mapping]
ids = [x[1] for x in mapping]

In [ ]:
# Connect
cli = FrameClient()
cli.connect(alias)

In [ ]:
# Build url 
# http://132.180.116.106/?command=dataquery&uri=dl:avg_top&format=toa5&mode=since-time&p1=2015-11-18
urlMask = "http://{0}/?command=dataquery&uri=dl:{1}&format=toa5&mode=since-time&p1={2}"
node = cli.getNode(folderId)
if node['rec_end']:
    # YYYY-MM-DD T:HH:MM:SS.
    rec_end = node['rec_end'].strftime('%Y-%m-%dT%H:%M:%S.00')
else:
    rec_end = "2000-01-01"
url = urlMask.format(host,table,rec_end)
# Read values 
print("Getting records since:{0}".format(rec_end))

In [ ]:
dataFrame = cli.read_toa5(url,'Etc/GMT-1')

In [ ]:
# Import values 
cli.writeFrame(ids,dataFrame[cols])

In [ ]:
cli.disconnect()