yaml_to_database (class)¶
- class fundamentals.mysql.yaml_to_database(log, dbConn, pathToInputDir=False, settings=False, deleteFiles=False)[source][source]¶
Bases:
objectTake key-values from yaml files including a tablename(s) and add them to a mysql database table
Key Arguments
log– loggersettings– the settings dictionarypathToInputDir– path to the directory containing the yaml files that will be added to the database table(s). Default FalsedbConn– connection to database to add the content todeleteFiles- - delete the yamls files once their content has been added to the database. Default * False*
Usage
To setup your logger, settings and database connections, please use the
fundamentalspackage (see tutorial here https://fundamentals.readthedocs.io/en/master/initialisation.html).To initiate a
yaml2dbobject, use the following:```python from fundamentals.mysql import yaml_to_database yaml2db = yaml_to_database(
log=log, settings=settings, dbConn=dbConn, pathToInputDir=”/path/to/yaml/directory”, deleteFiles=False
)¶
And here’s an example of the content in a yaml file that this
yaml2dbobject can parse:`yaml title: Why you should do most of your text editing in : Sublime Text | Sublime Text Tips url: http://sublimetexttips.com/why-you-should-do-most-of-your-text-editing-in-sublime-text/?utm_source=drip&utm_medium=email&utm_campaign=editor-proliferation kind: webpage subtype: article table: web_articles,podcasts `Methods
- add_yaml_file_content_to_database(filepath, deleteFile=False)[source][source]¶
given a file to a yaml file, add yaml file content to database
Key Arguments
filepath– the path to the yaml filedeleteFile– delete the yaml file when its content has been added to the database. Default False
Return
None
Usage
To parse and import the contents of a single yaml file into the database, use the following:
```python from fundamentals.mysql import yaml_to_database # PARSE YAML FILE CONTENTS AND ADD TO DATABASE yaml2db = yaml_to_database(
log=log, settings=settings, dbConn=dbConn
) yaml2db.add_yaml_file_content_to_database(
filepath=${1:”/path/to/file.yaml”}, deleteFile=True
)¶
- ingest()[source][source]¶
ingest the contents of the directory of yaml files into a database
Return
None
Usage
To import an entire directory of yaml files into a database, use the following:
```python from fundamentals.mysql import yaml_to_database yaml2db = yaml_to_database(
log=log, settings=settings, dbConn=dbConn, pathToInputDir=”/path/to/yaml/directory”, deleteFiles=False