absfuyu.tools.converter module

Absufyu: Converter

Convert stuff

Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)

Feature:

  • Text2Chemistry

  • Str2Pixel

  • Base64EncodeDecode

class absfuyu.tools.converter.Base64EncodeDecode[source]

Bases: BaseClass

Encode and decode base64

Added in version 3.0.0

static encode(data: str) str[source]

Base64 encode

static decode(data: str) str[source]

Base64 decode

static encode_image(img_path: Path | str, data_tag: bool = False) str[source]

Encode image file into base64 string

Parameters:
  • img_path (Path | str) – Path to image

  • data_tag (bool, optional) – Add data tag before base64 string, by default False

Returns:

Encoded image

Return type:

str

Added in version 4.1.0

class absfuyu.tools.converter.Text2Chemistry[source]

Bases: BaseClass

property unvailable_characters: set[str]

Characters that can not be converted (unvailable chemistry symbol)

Returns:

Set of unvailable characters

Return type:

set[str]

convert(text: str) list[list[ChemistryElement]] | list[source]

Convert text to chemistry symbol

Parameters:

text (str) – Desired text

Returns:

Converted text (empty list when failed to convert)

Return type:

list[list[ChemistryElement]] | list

Raises:

ValueError – When text contains digit, whitespaces, …

static beautify_result(result: list[list[ChemistryElement]] | list) str[source]

Beautify the result from Text2Chemistry.convert()

Parameters:

result (list[list[ChemistryElement]] | list) – Convert Text2Chemistry.convert() result

Returns:

Beautified output

Return type:

str

Added in version 4.2.0

class absfuyu.tools.converter.Str2Pixel(str_data: str, *, pixel_size: int = 2, pixel_symbol_overwrite: str | None = None)[source]

Bases: BaseClass

Convert str into pixel

Parameters:
  • str_data (str) –

    Pixel string data (Format: <number_of_pixel><color_code>)
    Example: 50w20b = 50 white pixels and 20 black pixels

  • pixel_size (int, optional) – Pixel size, by default 2

  • pixel_symbol_overwrite (str | None, optional) – Overwrite pixel symbol, by default None

PIXEL = '█'
convert(line_break: bool = True) str[source]

Convert data into pixel

Parameters:

line_break (bool, optional) – Add \n at the end of line, by default True

Returns:

Converted colored pixels

Return type:

str