list_of_dictionaries (class)¶
- class fundamentals.renderer.list_of_dictionaries(log, listOfDictionaries, reDatetime=False)[source][source]¶
Bases:
objectThe dataset object is a list of python dictionaries. Using this class, the data can be rendered as various list and markup formats
Key Arguments
log– loggerlistOfDictionaries– the list of dictionaries to renderreDatetime– a pre-compiled datetime regex. Default *False*fss
Usage
To initialise the dataset object:
- {
“owner”: “daisy”, “pet”: “dog”, “address”: “belfast, uk”
}, {
“owner”: “john”, “pet”: “snake”, “address”: “the moon”
}, {
“owner”: “susan”, “pet”: “crocodile”, “address”: “larne”
}
]
from fundamentals.renderer import list_of_dictionaries dataSet = list_of_dictionaries(
log=log, listOfDictionaries=dataList
)¶
Methods
Properties
- csv(filepath=None)[source][source]¶
Render the data in CSV format
Key Arguments
filepath– path to the file to write the csv content to. Default None
Return
renderedData– the data rendered in csv format
Usage
To render the data set as csv:
`python print(dataSet.csv()) ``text owner,pet,address daisy,dog,"belfast, uk" john,snake,the moon susan,crocodile,larne `and to save the csv rendering to file:
`python dataSet.csv("/path/to/myfile.csv") `
- json(filepath=None)[source][source]¶
Render the data in json format
Key Arguments
filepath– path to the file to write the json content to. Default None
Return
renderedData– the data rendered as json
Usage
To render the data set as json:
`python print(dataSet.json()) `- {
“address”: “belfast, uk”, “owner”: “daisy”, “pet”: “dog”
}, {
“address”: “the moon”, “owner”: “john”, “pet”: “snake”
}, {
“address”: “larne”, “owner”: “susan”, “pet”: “crocodile”
}
]¶
and to save the json rendering to file:
`python dataSet.json("/path/to/myfile.json") `
- markdown(filepath=None)[source][source]¶
Render the data as a markdown table
Key Arguments
filepath– path to the file to write the markdown to. Default None
Return
renderedData– the data rendered as a markdown table
Usage
To render the data set as a markdown table:
`python print(dataSet.markdown()) ``markdown | owner | pet | address | |:-------|:-----------|:-------------| | daisy | dog | belfast, uk | | john | snake | the moon | | susan | crocodile | larne | `and to save the markdown table rendering to file:
`python dataSet.table("/path/to/myfile.md") `
- mysql(tableName, filepath=None, createStatement=None)[source][source]¶
Render the dataset as a series of mysql insert statements
Key Arguments
tableName– the name of the mysql db table to assign the insert statements to.filepath– path to the file to write the mysql inserts content to. Default None
createStatement
Return
renderedData– the data rendered mysql insert statements (string format)
Usage
`python print(dataSet.mysql("testing_table")) `this output the following:
`plain INSERT INTO `testing_table` (address,dateCreated,owner,pet) VALUES ("belfast, uk" ,"2016-09-14T16:21:36" ,"daisy" ,"dog") ON DUPLICATE KEY UPDATE address="belfast, uk", dateCreated="2016-09-14T16:21:36", owner="daisy", pet="dog" ; INSERT INTO `testing_table` (address,dateCreated,owner,pet) VALUES ("the moon" ,"2016-09-14T16:21:36" ,"john" ,"snake") ON DUPLICATE KEY UPDATE address="the moon", dateCreated="2016-09-14T16:21:36", owner="john", pet="snake" ; INSERT INTO `testing_table` (address,dateCreated,owner,pet) VALUES ("larne" ,"2016-09-14T16:21:36" ,"susan" ,"crocodile") ON DUPLICATE KEY UPDATE address="larne", dateCreated="2016-09-14T16:21:36", owner="susan", pet="crocodile" ; `To save this rendering to file use:
`python dataSet.mysql("testing_table", "/path/to/myfile.sql") `
- reST(filepath=None)[source][source]¶
Render the data as a resturcturedText table
Key Arguments
filepath– path to the file to write the table to. Default None
Return
renderedData– the data rendered as a resturcturedText table
Usage
To render the data set as a resturcturedText table:
`python print(dataSet.reST()) ``text +--------+------------+--------------+ | owner | pet | address | +========+============+==============+ | daisy | dog | belfast, uk | +--------+------------+--------------+ | john | snake | the moon | +--------+------------+--------------+ | susan | crocodile | larne | +--------+------------+--------------+ `and to save the table rendering to file:
`python dataSet.reST("/path/to/myfile.rst") `
- table(filepath=None)[source][source]¶
Render the data as a plain text table
Key Arguments
filepath– path to the file to write the table to. Default None
Return
renderedData– the data rendered as a plain text table
Usage
To render the data set as a plain text table:
`python print(dataSet.table()) ``text +--------+------------+--------------+ | owner | pet | address | +========+============+==============+ | daisy | dog | belfast, uk | | john | snake | the moon | | susan | crocodile | larne | +--------+------------+--------------+ `and to save the table rendering to file:
`python dataSet.table("/path/to/myfile.ascii") `
- yaml(filepath=None)[source][source]¶
Render the data in yaml format
Key Arguments
filepath– path to the file to write the yaml content to. Default None
Return
renderedData– the data rendered as yaml
Usage
To render the data set as yaml:
`python print(dataSet.yaml()) ````yaml - address: belfast, uk
owner: daisy pet: dog
address: the moon owner: john pet: snake
address: larne owner: susan pet: crocodile
and to save the yaml rendering to file:
`python dataSet.json("/path/to/myfile.yaml") `