absfuyu.general.content module
Absfuyu: Content
Handle .txt file
Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)
Usage:
>>> from absfuyu.general.content import ContentLoader
- class absfuyu.general.content.ContentLoader(file_path: Path | str, characteristic_detect: bool = True, tag_dictionary: dict | None = None, *, comment_symbol: str = '#', split_symbol: str = '|', tag_separate_symbol: str = ',')[source]
Bases:
BaseClassThis load data from
.txtfileContent format:
<content><split_symbol><tags separated by <tag_separate_symbol>>- content_format() str[source]
Shows current content format
- Returns:
Current content format
- Return type:
str
Example:
>>> ContentLoader(".").content_format() # This line will be ignored <content> | <tag1>, <tag2>
- load_content() LoadedContent[source]
Load data into a list of
Content- Returns:
Loaded content
- Return type:
- class absfuyu.general.content.Content(data: list)[source]
Bases:
BaseClassContain data
- Data format: list[str, list[str]]
where:
str: data;list[str]: data tags
- unidecoded() Self[source]
Convert data through
unidecodepackage- Returns:
unidecodedContent- Return type:
- short_form(separator: str = ',') str[source]
Short form show only first item when separated by
separator- Parameters:
separator (str) – Default:
","- Returns:
Short form
- Return type:
str
- handle_address(address_separator: str = ',', *, first_item_not_address: bool = True) Self[source]
Handle
self.dataas address and then update the address intoself.tag- Parameters:
address_separator (str) –
Split the address by which character(Default:",")first_item_not_address (bool) – Set to
Falsewhen<splited data>[0]is not part of an address
- Returns:
Handled Content
- Return type:
Example:
>>> test = "Shop A, 22 ABC Street, DEF District, GHI City" >>> # After handle_address() ["Shop A", "22 ABC Street", "DEF District", "GHI City"]
>>> # After handle_address(first_item_not_address = False) ["22 ABC Street", "DEF District", "GHI City"]
- class absfuyu.general.content.LoadedContent(iterable=(), /)[source]
Bases:
list[Content],ShowAllMethodsMixinContain list of
Content- apply(func) Self[source]
Apply function to each entry
- Parameters:
func (Callable) – Callable function
- Return type:
- classmethod load_from_json(file: Path) Self[source]
Use this method to load data from
.jsonfile fromto_json()method- Parameters:
file (Path) – Path to
.jsonfile- Returns:
Loaded content from
.jsonfile- Return type:
- property tags: list
A list contains all available tag
- filter(tag: str) Self[source]
Filter out entry with
tag- Parameters:
tag (str) – Tag to filter
- Return type:
- find(keyword: str) Self[source]
Return all entries that include
keyword- Parameters:
keyword (str) – Keyword to find
- Return type:
- short_form(separator: str = ',') list[str][source]
Shows only first item when separated by
separatorofContent.data- Parameters:
separator (str) – Default:
","- Returns:
Short form
- Return type:
list[str]
- pick_one(tag: str | None = None) Content[source]
Pick a random entry
- Parameters:
tag (str | None) – Pick a random entry with
tag(Default: None)- Returns:
Random entry
- Return type:
- handle_address(address_separator: str = ',', *, first_item_not_address: bool = True) Self[source]
Execute
Content.handle_address()on everyself.dataofContent- Parameters:
address_separator (str) –
Split the address by which character(Default:",")first_item_not_address (bool) – Set to
Falsewhen<splited data>[0]is not part of an address
- Returns:
Handled Content
- Return type:
Example:
>>> test = "Shop A, 22 ABC Street, DEF District, GHI City" >>> # After handle_address() ["Shop A", "22 ABC Street", "DEF District", "GHI City"]
>>> # After handle_address(first_item_not_address = False) ["22 ABC Street", "DEF District", "GHI City"]