Skip to content

Commit 9ce53f0

Browse files
committed
rename Quest.rookgaard to is_rookgaard_quest
1 parent 5a5c722 commit 9ce53f0

9 files changed

Lines changed: 209 additions & 199 deletions

File tree

CHANGELOG.md

Lines changed: 180 additions & 179 deletions
Large diffs are not rendered by default.

docs/api/models/book.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: tibiawikisql.models.book

mkdocs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ nav:
125125
- Package Index: api/models/index.md
126126
- Base: api/models/base.md
127127
- Achievement: api/models/achievement.md
128+
- Book: api/models/book.md
128129
- Charm: api/models/charm.md
129130
- Creature: api/models/creature.md
130131
- House: api/models/house.md

tibiawikisql/models/item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class Book(WikiEntry, WithStatus, WithVersion, RowModel, table=BookTable):
305305

306306
name: str
307307
"""The name of the book."""
308-
book_type: str | None = None
308+
book_type: str
309309
"""The type of item this book can be found in."""
310310
item_id: int | None = None
311311
"""The ID of the item this book is written in."""
@@ -327,8 +327,8 @@ def insert(self, conn: Connection | Cursor) -> None:
327327
super().insert(conn)
328328
return
329329

330-
book_table = Table(self.table.__tablename__)
331-
item_table = Table(ItemTable.__tablename__)
330+
book_table = self.table.__table__
331+
item_table = ItemTable.__table__
332332

333333
q = (
334334
Query.into(book_table)

tibiawikisql/models/quest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Quest(WikiEntry, WithStatus, WithVersion, RowModel, table=QuestTable):
167167
"""The name of the quest."""
168168
location: str | None
169169
"""The location of the quest."""
170-
rookgaard: bool
170+
is_rookgaard_quest: bool
171171
"""Whether this quest is in Rookgaard or not."""
172172
is_premium: bool
173173
"""Whether this quest requires a Premium account or not."""

tibiawikisql/parsers/creature.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import re
2-
from typing import Any, ClassVar
2+
from typing import Any, ClassVar, TYPE_CHECKING
33

44
import mwparserfromhell
5-
from mwparserfromhell.nodes import Template
65

76
import tibiawikisql.schema
87
from tibiawikisql.api import Article
@@ -26,6 +25,9 @@
2625
strip_code,
2726
)
2827

28+
if TYPE_CHECKING:
29+
from mwparserfromhell.nodes import Template
30+
2931

3032
def parse_maximum_damage(value: str) -> dict[str, int]:
3133
"""Parse the maximum damage template from TibiaWiki.

tibiawikisql/parsers/quest.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@
77
from tibiawikisql.models.quest import ItemReward, Quest, QuestCreature, QuestDanger, QuestReward
88
from tibiawikisql.parsers.base import AttributeParser
99
from tibiawikisql.parsers import BaseParser
10-
import tibiawikisql.schema
10+
from tibiawikisql.schema import QuestTable
1111
from tibiawikisql.utils import clean_links, parse_boolean, parse_integer
1212

1313
link_pattern = re.compile(r"\[\[([^|\]]+)")
1414

1515

16-
def parse_links(value):
16+
def parse_links(value: str) -> list[str]:
1717
"""Find all the links in a string and returns a list of them.
1818
19-
Parameters
20-
----------
21-
value: :class:`str`
22-
A string containing links.
19+
Args:
20+
value: A string containing links.
2321
24-
Returns
25-
-------
26-
list(:class:`str`):
22+
Returns:
2723
The links found in the string.
2824
2925
"""
@@ -34,12 +30,12 @@ class QuestParser(BaseParser):
3430
"""Parser for quests."""
3531

3632
model = Quest
37-
table = tibiawikisql.schema.QuestTable
33+
table = QuestTable
3834
template_name = "Infobox_Quest"
3935
attribute_map: ClassVar = {
4036
"name": AttributeParser.required("name", html.unescape),
4137
"location": AttributeParser.optional("location", clean_links),
42-
"rookgaard": AttributeParser.optional("rookgaardquest", parse_boolean, False),
38+
"is_rookgaard_quest": AttributeParser.optional("rookgaardquest", parse_boolean, False),
4339
"type": AttributeParser.optional("type"),
4440
"quest_log": AttributeParser.optional("log", parse_boolean),
4541
"legend": AttributeParser.optional("legend", clean_links),

tibiawikisql/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class BookTable(Table):
207207
article_id = Column(Integer, primary_key=True)
208208
title = Column(Text, unique=True)
209209
name = Column(Text)
210-
book_type = Column(Text)
210+
book_type = Column(Text, nullable=False)
211211
item_id = Column(ForeignKey(Integer, "item", "article_id"), index=True)
212212
location = Column(Text)
213213
blurb = Column(Text)
@@ -548,7 +548,7 @@ class QuestTable(Table):
548548
title = Column(Text, no_case=True, unique=True)
549549
name = Column(Text, index=True, no_case=True)
550550
location = Column(Text)
551-
rookgaard = Column(Boolean, default=False)
551+
is_rookgaard_quest = Column(Boolean, default=False)
552552
type = Column(Text, default="quest", index=True)
553553
quest_log = Column(Boolean, default=False)
554554
legend = Column(Text)

tibiawikisql/server.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from starlette.responses import JSONResponse
1010

1111
from tibiawikisql.api import WikiClient
12-
from tibiawikisql.models import Achievement, Charm, Creature, House, Imbuement, Item, Key, Mount, Npc, Outfit, Quest, \
12+
from tibiawikisql.models import Achievement, Book, Charm, Creature, House, Imbuement, Item, Key, Mount, Npc, Outfit, \
13+
Quest, \
1314
Spell, \
1415
Update, \
1516
World
@@ -82,6 +83,14 @@ def get_wiki_achievement(
8283
return None
8384
return AchievementParser.from_article(article)
8485

86+
@db_router.get("/books/{title}")
87+
def get_book(
88+
conn: Conn,
89+
title: str,
90+
) -> Book | None:
91+
return Book.get_by_title(conn, title)
92+
93+
8594

8695
@db_router.get("/charms/{title}")
8796
def get_charm(

0 commit comments

Comments
 (0)