yaml_to_database (class) ∞
-
class
yaml_to_database
(log, dbConn, pathToInputDir=False, settings=False, deleteFiles=False)[source] ∞ Bases:
object
Take 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
fundamentals
package (see tutorial here).To initiate a
yaml2db
object, use the following: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
yaml2db
object can parse: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)given a file to a yaml file, add yaml file content to database
ingest
()ingest the contents of the directory of yaml files into a database
-
add_yaml_file_content_to_database
(filepath, deleteFile=False)[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:
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] ∞ 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:
from fundamentals.mysql import yaml_to_database yaml2db = yaml_to_database( log=log, settings=settings, dbConn=dbConn, pathToInputDir="/path/to/yaml/directory", deleteFiles=False ) yaml2db.ingest()