This demos shows how to use the bayeos.cli.SimpleClient
class to connect to a BayEOS Server. The class implements basic functionalities with native python tpyes for read and write functions. There are no dependencies to external libraries.
The SimpleClient class can be imported as any other python class.
In [1]:
from bayeos.cli import SimpleClient
We need an instance of it:
In [2]:
bayeos = SimpleClient()
Let us now open the connection to our freely available BayEOS Server and save the connection information in a encrypted file on our local disk. We can pick the connection information later on by an alias.
In [3]:
bayeos.connect(url="http://bayeos.bayceer.uni-bayreuth.de/BayEOS-Server/XMLServlet",user="gast",password="gast",save_as="guest@bayeos")
Out[3]:
A connection can be closed by calling disconnect()
In [4]:
bayeos.disconnect()
Out[4]:
Just call the connect()
function with the parameter listConnections=True
to list all available connection alias.
In [5]:
bayeos.connect(listConnections=True)
Out[5]:
Use the alias to reopen the connection. The following call retrieves the alias in $HOME/.bayeos.pwd
and decryptes it with a key stored in $HOME/.bayeos.pwd_key
.
In [6]:
bayeos.connect(url="guest@bayeos")
Out[6]:
The basic navigation interface is loosely based on the UNIX
file sytem navigation commands.
We can list the content of a working directory by calling the ls()
function. The output shows the id, name, type, first and last result date of folders and series rendered as a table.
In [7]:
bayeos.ls()
Use the cd()
function to change the current working directory. You need to pass in the folder id.
In [8]:
bayeos.cd(14333)
Please call cd('..')
to switch into the parent directory.
In [ ]:
bayeos.cd('..')
The pwd()
function prints the current working directory path.
In [ ]:
bayeos.pwd()
Please close the connection before you shut down the kernel.
In [9]:
bayeos.disconnect()
Out[9]:
The SimpleClient provides methods to create, read, update and delete a series.
Import the package and open a new connection with write privileges.
In [11]:
from bayeos.cli import SimpleClient
bayeos = SimpleClient()
bayeos.connect(url='myAlias')
Out[11]:
To create three series and return the ids as a list we use pythons handy list comprehension functionality.
In [12]:
ids = [bayeos.createSeries("Dummy" + x) for x in ["A","B","C"] ]
Import some observation records as list of lists. The first column contains the observation time by convention.
In [13]:
from datetime import datetime, timedelta
now = datetime.utcnow()
past = now + timedelta(minutes=-10)
data = [[now,2.1,2.2,2.3],[past,1.1,1.2,1.3]]
bayeos.writeSeries(ids,data)
In [14]:
(header, data) = bayeos.getSeries(ids,interval='today')
In [15]:
header
Out[15]:
In [16]:
data
Out[16]:
You can call the writeSeries function with overwrite=True
to update a value.
In [17]:
data = [[now,3.1,3.2,3.3]]
bayeos.writeSeries(ids,data,overwrite=True)
(header, data) = bayeos.getSeries(ids,interval='today')
In [18]:
data
Out[18]:
Drop all created series by id.
In [19]:
[bayeos.deleteSeries(x) for x in ids]
Out[19]:
In [ ]:
bayeos.disconnect()