Writers¶
This section describes classes for writing data in various formats, such as CSV or Excel files.
Writer¶
-
class
Writer
(type, DEBUG=False)¶ Bases:
object
This object handles writing structured data in JSON format in tabular formats, such as CSV or Microsoft Excel (.xlsx).
Parameters: - type (str) – String representation of writer type, used in logging messages.
- DEBUG (bool) – Enables/disables debugging output.
-
_get_headers
(data)¶ This function returns sorted list of column headers (dictionary keys). :param list|dict data: List or dict of dictionaries containing common keys. :return: List of headers.
-
combine_data
(data)¶ Function for combining data from multiple sections. Each section represents data gathered by some of the get_ functions. Each returned dataset includes common headers identifying device, from which the data originates.
Parameters: data (list) – List of dictionaries, content of single section Returns: (list) section_headers, (list) section_content
-
combine_device_data
(data)¶
-
json_to_lists
(data)¶ This function transfers list of dictionaries into two lists, one containing the column headers (keys of dictionary) and the other containing individual list of values (representing rows).
Parameters: data (list) – List of dictionaries with common structure Returns: Dict with “headers” list and “list_data” list containing rows.
ExcelWriter¶
-
class
ExcelWriter
¶ Bases:
nuaal.Writers.Writer.Writer
This class provides functions for writing the retrieved data in Microsoft Excel format, .xlsx.
-
create_workbook
(path, filename)¶ Function for creating Excel Workbook based on path and file name.
Parameters: - path (str) – System path to Excel file
- filename (str) – Name of the Excel file.
Returns: Instance of
xlsxwriter
workbook object.
-
write_data
(workbook, data)¶ Function for writing entire content of device data, divided into sections based on get_ command used. :param workbook: Reference of the
xlsxwriter
workbook object. :param dict data: Content of device.data variable, which holds all retrieved info. :return:None
-
write_json
(workbook, data, worksheetname=None, headers=None)¶ Function for writing JSON-like data to worksheet.
Parameters: - workbook – Reference of the
xlsxwriter
workbook object. - data –
- worksheetname (str) – Name of the worksheet
- headers (list) – List of column headers.
Returns: None
- workbook – Reference of the
-
write_list
(workbook, data, worksheetname=None, headers=None)¶ Function for creating worksheet inside given workbook and writing provided data.
Parameters: - workbook – Reference of the
xlsxwriter
workbook object. - data (list) – List of lists, where each list represents one row in the worksheet.
- worksheetname (str) – Name of the worksheet.
- headers (list) – List of column headers.
Returns: None
- workbook – Reference of the
-