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. |
write_parsing_error |
Write a parsing error entry to a log file. |
parse_articles |
Parse category articles into the database. |
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', parsers.AchievementParser, no_images=True), 'spells': Category('Spells', parsers.SpellParser, generate_map=True), 'items': Category('Objects', parsers.ItemParser, generate_map=True), 'creatures': Category('Creatures', parsers.CreatureParser, generate_map=True), 'books': Category('Book Texts', parsers.BookParser, no_images=True), 'keys': Category('Keys', parsers.KeyParser, no_images=True, depends_on=('items',)), 'npcs': Category('NPCs', parsers.NpcParser, generate_map=True), 'imbuements': Category('Imbuements', parsers.ImbuementParser, extension='.png'), 'quests': Category('Quest Overview Pages', parsers.QuestParser, no_images=True), 'houses': Category('Player-Ownable Buildings', parsers.HouseParser, no_images=True), 'charms': Category('Charms', parsers.CharmParser, extension='.png'), 'outfits': Category('Outfits', parsers.OutfitParser, no_images=True), 'worlds': Category('Game Worlds', parsers.WorldParser, no_images=True, include_deprecated=True), 'mounts': Category('Mounts', parsers.MountParser), 'updates': Category('Updates', parsers.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
write_parsing_error
¶
write_parsing_error(file: TextIO, *, category: str, article: Article, error: ArticleParsingError) -> None
Write a parsing error entry to a log file.
Source code in tibiawikisql/generation.py
parse_articles
¶
parse_articles(conn: Connection, data_store: dict[str, Any], enabled_categories: set[str], parsing_errors_log: TextIO | None = None) -> int
Parse category articles into the database.
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, include_deprecated_images: bool = False, skip_categories: tuple[str, ...] = (), parsing_errors_file: str | None = None) -> None
Generate a complete TibiaWiki SQLite database.
Source code in tibiawikisql/generation.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |