Bootstrap - unihan_db.bootstrap

Fetch, extract, transform, and load UNIHAN into database.

unihan_db.bootstrap.setup_logger(logger=None, level='INFO')[source]

Configure logging for CLI use.

Return type:

None

Parameters:
  • logger (logging.Logger) – instance of logger

  • level (str) – logging level, e.g. ‘INFO’

unihan_db.bootstrap.is_bootstrapped(metadata)[source]

Return True if cihai is correctly bootstrapped.

Return type:

bool

unihan_db.bootstrap.bootstrap_data(options=None)[source]

Fetch, download, and export UNIHAN data in dictionary format.

Return type:

Optional[UntypedNormalizedData]

unihan_db.bootstrap.bootstrap_unihan(session, options=None)[source]

Bootstrap UNIHAN to database.

Return type:

None

unihan_db.bootstrap.setup_orm_mappings(mapper, class_)[source]

Add special methods to Base declarative model used in Unihan DB.

Return type:

None

unihan_db.bootstrap.to_dict(obj, found=None)[source]

Return dictionary of an SQLAlchemy Query result.

Supports recursive relationships.

Return type:

Dict[str, object]

Parameters:
Returns:

dictionary representation of a SQLAlchemy query

Return type:

dict

unihan_db.bootstrap.add_to_dict(b)[source]

Add to_dict() method to SQLAlchemy Base object.

Return type:

Any

Parameters:

b (declarative_base()) – SQLAlchemy Base class

unihan_db.bootstrap.get_session(engine_url='sqlite:///{user_data_dir}/unihan_db.db')[source]

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.

Return type:

scoped_session[Any]

Parameters:

engine_url (str) – SQLAlchemy engine string