Bootstrap - unihan_db.bootstrap¶
Fetch, extract, transform, and load UNIHAN into database.
-
unihan_db.bootstrap.setup_logger(logger=None, level='INFO')¶
Configure logging for CLI use.
- Parameters:
logger (
logging.Logger) – instance of loggerlevel (str) – logging level, e.g. ‘INFO’
- Return type:
-
unihan_db.bootstrap.is_bootstrapped(metadata)¶
Return True if cihai is correctly bootstrapped.
- Parameters:
metadata (MetaData)
- Return type:
-
unihan_db.bootstrap.bootstrap_data(options=None)¶
Fetch, download, and export UNIHAN data in dictionary format.
-
unihan_db.bootstrap.bootstrap_unihan(session, options=None)¶
Bootstrap UNIHAN to database.
-
unihan_db.bootstrap.setup_orm_mappings(mapper, class_)¶
Add special methods to Base declarative model used in Unihan DB.
-
unihan_db.bootstrap.to_dict(obj, found=None)¶
Return dictionary of an SQLAlchemy Query result.
Supports recursive relationships.
- Parameters:
obj (
sqlalchemy.orm.query.Queryresult object) – SQLAlchemy Query resultfound (
set) – recursive parameters
- Returns:
dictionary representation of a SQLAlchemy query
- Return type:
-
unihan_db.bootstrap.add_to_dict(b)¶
Add
to_dict()method to SQLAlchemy Base object.- Parameters:
b (
declarative_base()) – SQLAlchemy Base class- Return type:
-
unihan_db.bootstrap.get_session(engine_url='sqlite:///{user_data_dir}/unihan_db.db')¶
Return new SQLAlchemy session object from engine string.
engine_url accepts a string template variable for
{user_data_dir}, which is replaced to the XDG data directory for the user running the script process. This variable is only useful for SQLite, where file paths are used for the engine_url.