Table of Contents

Brewer JSON Python Module

The Brewer JSON Python Module provides the functions to connect to the RBCC-E database and to download data of the different Brewer equipments.

We describe here the functions implemented in brewerjson.py module. The last version of the python module is available from rbcce subversion repository.

Installation

Brewer JSON library can be imported from python code adding the path to brewerjson.py module to the Python path (list of directories Python goes through to search for modules and files):

import sys
sys.path.append("/home/to/module/")

By default the sys.path variable includes the current directory, so if brewerjson.py is in the same directory as the Python script, the module can be directly imported.

Alternatively, you can download brewer.py file to the standard location for third-party Python modules. This location varies by platform and by how you built/installed Python itself. Typical locations are shown in the following table:

Platform Standard installation location
Windows C:\PythonXY\Lib\site-packages
Unix /usr/local/lib/pythonX.Y/site-packages

Functions

The functions of this module are:

Field Description
getDataList() Retrieve a list of dictionaries with data from RBCC-E between two dates.
writejson() Write list of dictionaries (measures, config,..) to file.
readjson() Read list of dictionaries (measures, config,..) from file.

getDataList()

This function retrieve a list of dictionaries with data of the registered brewers at the RBCC-E database. Arguments are berwerid, user, password, function, date1 and date2. If date2 is omitted the function returns only data of the day data1.

The returned dictionaries structures depend on the function argument value:

function Dictionaries
'DS' measure
'SL' measure
'ConfigbyDate' config

Example

  import brewerjson
  import datetime
  
  d1=datetime.date(2014,10,01)
  d2=datetime.date(2014,10,02)
  data=brewerjson.getDataList(185,'user,'password','DS',d1,d2)

writejson()

This function save a list of dictionaries to file. The values of 'gmt' and 'date' are transformed to strings.

Example

  import brewerjson
  import datetime
  
  d1=datetime.date(2014,10,01)
  d2=datetime.date(2014,10,02)
  data=brewerjson.getDataList(185,'user,'password','DS',d1,d2)
  brewerjson.getdata(data,'output.txt')

This function accepts two input parameters: 'data' and 'file'.

readjson()

This function read a file containing a list of dictionaries.

Example

  import brewerjson
  import datetime
  
  brewerjson.getdata('input.txt')