Generation
tibiawikisql.generation
¶
Functions related to generating a database dump from TibiaWiki.
Classes:
| Name | Description |
|---|---|
Category |
Defines the article groups to be fetched. |
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. |
get_cache_info |
Get a mapping of the last edit times of images stored in the cache. |
save_cache_info |
Store the last edit times of images stored in the cache. |
fetch_image |
Fetch an image from TibiaWiki and saves it the disk. |
save_images |
Fetch and save the images of articles of a certain category. |
save_maps |
Save the map files from TibiaMaps GitHub repository. |
generate_outfit_image_names |
Generate the list of image names to extract for outfits, as well as their parametrized information. |
save_outfit_images |
Save outfit images into the database. |
fetch_category_entries |
Fetch a list of wiki entries in a certain category. |
fetch_images |
Fetch all images for fetched articles. |
generate_spell_offers |
Fetch and save the spell offers from the spell data module. |
Attributes:
| Name | Type | Description |
|---|---|---|
ConnCursor |
Type alias for both sqlite3 Cursor or Connection objects. |
|
OUTFIT_NAME_TEMPLATES |
The templates for image filenames for outfits. |
|
OUTFIT_ADDON_SEQUENCE |
The sequence of addon types to iterate. |
|
OUTFIT_SEX_SEQUENCE |
The sequence of outfit sexes to iterate. |
|
CATEGORIES |
The categories to fetch and generate objects for. |
ConnCursor
module-attribute
¶
ConnCursor = Cursor | Connection
Type alias for both sqlite3 Cursor or Connection objects.
OUTFIT_NAME_TEMPLATES
module-attribute
¶
OUTFIT_NAME_TEMPLATES = [
"Outfit %s Male.gif",
"Outfit %s Male Addon 1.gif",
"Outfit %s Male Addon 2.gif",
"Outfit %s Male Addon 3.gif",
"Outfit %s Female.gif",
"Outfit %s Female Addon 1.gif",
"Outfit %s Female Addon 2.gif",
"Outfit %s Female Addon 3.gif",
]
The templates for image filenames for outfits.
OUTFIT_ADDON_SEQUENCE
module-attribute
¶
The sequence of addon types to iterate.
OUTFIT_SEX_SEQUENCE
module-attribute
¶
The sequence of outfit sexes to iterate.
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),
"npcs": Category("NPCs", NpcParser, generate_map=True),
"imbuements": Category(
"Imbuements", ImbuementParser, extension=".png"
),
"quests": Category(
"Quest Overview Pages", QuestParser, no_images=True
),
"house": Category(
"Player-Ownable Buildings",
HouseParser,
no_images=True,
),
"charm": 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,
)
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
|
Source code in tibiawikisql/generation.py
img_label
¶
article_label
¶
constraint
¶
Limit a string to a certain length if exceeded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string to constraint the length of. |
required |
limit
|
int
|
The length limit. |
required |
Returns:
| Type | Description |
|---|---|
str
|
If the string exceeds the limit, the same string is returned, otherwise it is cropped. |
Source code in tibiawikisql/generation.py
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
get_cache_info
¶
Get a mapping of the last edit times of images stored in the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_name
|
str
|
The name of the folder containing the stored images. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, datetime]
|
A dictionary, where each key is an image filename and its value is its upload date to the wiki. |
Source code in tibiawikisql/generation.py
save_cache_info
¶
Store the last edit times of images stored in the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_name
|
str
|
The name of the folder containing the stored images. |
required |
cache_info
|
dict[str, datetime]
|
A mapping of file names to their last upload date. |
required |
Source code in tibiawikisql/generation.py
fetch_image
¶
Fetch an image from TibiaWiki and saves it the disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The request session to use to fetch the image. |
required |
folder
|
str
|
The folder where the images will be stored locally. |
required |
image
|
Image
|
The image data. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
The bytes of the image. |
Source code in tibiawikisql/generation.py
save_images
¶
save_images(
conn: Connection, key: str, value: Category
) -> None
Fetch and save the images of articles of a certain category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Connection to the database. |
required |
key
|
str
|
The name of the data store key to use. |
required |
value
|
Category
|
The category of the images. |
required |
Source code in tibiawikisql/generation.py
save_maps
¶
save_maps(con: ConnCursor) -> None
Save the map files from TibiaMaps GitHub repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con
|
ConnCursor
|
A connection or cursor to the database. |
required |
Source code in tibiawikisql/generation.py
generate_outfit_image_names
¶
generate_outfit_image_names(
rows: list[tuple[int, str]],
) -> tuple[list[str], dict[str, tuple[int, int, str]]]
Generate the list of image names to extract for outfits, as well as their parametrized information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
list[tuple[int, str]]
|
A list of article ID and title pairs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
titles |
list[str]
|
A list of filenames to download. |
image_info |
dict[str, tuple[int, int, str]]
|
A mapping of file names to their article ID, addon type and outfit sex. |
Source code in tibiawikisql/generation.py
save_outfit_images
¶
save_outfit_images(conn: ConnCursor) -> None
Save outfit images into the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
ConnCursor
|
A connection or cursor to the database. |
required |
Source code in tibiawikisql/generation.py
fetch_category_entries
¶
Fetch a list of wiki entries in a certain category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
The name of the TibiaWiki category. |
required |
exclude_titles
|
set[str] | None
|
Exclude articles matching these titles. |
None
|
Returns:
| Type | Description |
|---|---|
list[WikiEntry]
|
A list of entries contained in the category. |
Source code in tibiawikisql/generation.py
fetch_images
¶
fetch_images(conn: Connection) -> None
Fetch all images for fetched articles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
A connection to the database. |
required |
Source code in tibiawikisql/generation.py
generate_spell_offers
¶
generate_spell_offers(
conn: Connection, data_store: dict[str, Any]
) -> None
Fetch and save the spell offers from the spell data module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
A connection to the database. |
required |
data_store
|
dict[str, Any]
|
The data store containing information about generated articles. |
required |