fundamentals.renderer.list_of_dictionaries¶
Render a python list of dictionaries in various list and markup formats
- Author
David Young
Module Contents¶
Classes¶
The dataset object is a list of python dictionaries. Using this class, the data can be rendered as various list and markup formats |
API¶
- class fundamentals.renderer.list_of_dictionaries.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 Falsefss
Usage
To initialise the dataset object:
dataList = [ { "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 )
Initialization
- 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:
print(dataSet.csv())
owner,pet,address daisy,dog,"belfast, uk" john,snake,the moon susan,crocodile,larne
and to save the csv rendering to file:
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:
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:
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:
print(dataSet.markdown())
| owner | pet | address | |:-------|:-----------|:-------------| | daisy | dog | belfast, uk | | john | snake | the moon | | susan | crocodile | larne |
and to save the markdown table rendering to file:
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
print(dataSet.mysql("testing_table"))
this output the following:
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:
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:
print(dataSet.reST())
+--------+------------+--------------+ | owner | pet | address | +========+============+==============+ | daisy | dog | belfast, uk | +--------+------------+--------------+ | john | snake | the moon | +--------+------------+--------------+ | susan | crocodile | larne | +--------+------------+--------------+
and to save the table rendering to file:
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:
print(dataSet.table())
+--------+------------+--------------+ | owner | pet | address | +========+============+==============+ | daisy | dog | belfast, uk | | john | snake | the moon | | susan | crocodile | larne | +--------+------------+--------------+
and to save the table rendering to file:
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:
print(dataSet.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:
dataSet.json("/path/to/myfile.yaml")