Generation
tibiawikisql.generation
¶
Functions related to generating a database dump from TibiaWiki.
Classes:
| Name | Description |
|---|---|
Category |
Defines the article groups to be fetched. |
PostTask |
Represents a post-processing task and its category dependencies. |
Functions:
| Name | Description |
|---|---|
img_label |
Get the label to show in progress bars when iterating images. |
article_label |
Get the label to show in progress bar when iterating articles. |
constraint |
Limit a string to a certain length if exceeded. |
progress_bar |
Get a progress bar iterator. |
fetch_category_entries |
Fetch a list of wiki entries in a certain category. |
resolve_enabled_categories |
Resolve enabled categories including dependency-based auto-skips. |
warn_auto_skipped_categories |
Emit warnings for categories that were disabled due to dependencies. |
run_post_tasks |
Run post-processing tasks honoring dependency constraints. |
generate |
Generate a complete TibiaWiki SQLite database. |
Attributes:
| Name | Type | Description |
|---|---|---|
CATEGORIES |
The categories to fetch and generate objects for. |
CATEGORIES
module-attribute
¶
CATEGORIES = {
"achievements": Category(
"Achievements", AchievementParser, no_images=True
),
"spells": Category(
"Spells", SpellParser, generate_map=True
),
"items": Category(
"Objects", ItemParser, generate_map=True
),
"creatures": Category(
"Creatures", CreatureParser, generate_map=True
),
"books": Category(
"Book Texts", BookParser, no_images=True
),
"keys": Category(
"Keys",
KeyParser,
no_images=True,
depends_on=("items",),
),
"npcs": Category("NPCs", NpcParser, generate_map=True),
"imbuements": Category(
"Imbuements", ImbuementParser, extension=".png"
),
"quests": Category(
"Quest Overview Pages", QuestParser, no_images=True
),
"houses": Category(
"Player-Ownable Buildings",
HouseParser,
no_images=True,
),
"charms": Category(
"Charms", CharmParser, extension=".png"
),
"outfits": Category(
"Outfits", OutfitParser, no_images=True
),
"worlds": Category(
"Game Worlds",
WorldParser,
no_images=True,
include_deprecated=True,
),
"mounts": Category("Mounts", MountParser),
"updates": Category(
"Updates", UpdateParser, no_images=True
),
}
The categories to fetch and generate objects for.
Category
¶
Category(
name: str | None,
parser: type[BaseParser],
*,
no_images: bool = False,
extension: str = ".gif",
include_deprecated: bool = False,
generate_map: bool = False,
depends_on: tuple[str, ...] = (),
)
Defines the article groups to be fetched.
Class for internal use only, for easier autocompletion and maintenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the TibiaWiki category containing the articles. Doesn't need the |
required |
parser
|
type[BaseParser]
|
The parser class to use. |
required |
no_images
|
bool
|
Indicate that there is no image extraction from this category's items. |
False
|
extension
|
str
|
The filename extension for images. |
'.gif'
|
include_deprecated
|
bool
|
Whether to always include deprecated articles from this category. |
False
|
generate_map
|
bool
|
Whether to generate a mapping of article names to their article instance for later processing. |
False
|
depends_on
|
tuple[str, ...]
|
Category keys required to safely process this category. |
()
|
Source code in tibiawikisql/generation.py
PostTask
dataclass
¶
PostTask(
name: str,
callback: Callable[
[Connection, dict[str, Any], set[str]], None
],
dependencies: tuple[str, ...] = (),
)
Represents a post-processing task and its category dependencies.
img_label
¶
article_label
¶
Get the label to show in progress bar when iterating articles.
constraint
¶
progress_bar
¶
progress_bar(
iterable: Iterable[V] | None = None,
length: int | None = None,
label: str | None = None,
item_show_func: Callable[[V | None], str | None]
| None = None,
info_sep: str = " ",
width: int = 36,
) -> ProgressBar[V]
Get a progress bar iterator.
Source code in tibiawikisql/generation.py
fetch_category_entries
¶
Fetch a list of wiki entries in a certain category.
Source code in tibiawikisql/generation.py
resolve_enabled_categories
¶
Resolve enabled categories including dependency-based auto-skips.
Source code in tibiawikisql/generation.py
warn_auto_skipped_categories
¶
Emit warnings for categories that were disabled due to dependencies.
Source code in tibiawikisql/generation.py
run_post_tasks
¶
run_post_tasks(
conn: Connection,
data_store: dict[str, Any],
enabled_categories: set[str],
skip_images: bool,
) -> None
Run post-processing tasks honoring dependency constraints.
Source code in tibiawikisql/generation.py
generate
¶
generate(
conn: Connection,
skip_images: bool = False,
skip_deprecated: bool = False,
skip_categories: tuple[str, ...] = (),
) -> None
Generate a complete TibiaWiki SQLite database.