11from typing import Any , ClassVar
22
3+ import mwparserfromhell
34import tibiawikisql .schema
45from tibiawikisql .api import Article
56from tibiawikisql .models .npc import Npc , NpcDestination
@@ -87,7 +88,11 @@ def _parse_destinations(cls, value: str) -> list[tuple[str, int, str]]:
8788 Returns:
8889 A list of tuples, where each element is the name of the destination, the price and additional notes.
8990 """
90- template = find_template (value , "Transport" , partial = True )
91+ result = cls ._parse_transport_cells (value )
92+ if result :
93+ return result
94+
95+ template = find_template (value , "Transport" )
9196 if not template :
9297 return []
9398 result = []
@@ -104,4 +109,23 @@ def _parse_destinations(cls, value: str) -> list[tuple[str, int, str]]:
104109 result .append ((destination , price , notes ))
105110 return result
106111
112+ @classmethod
113+ def _parse_transport_cells (cls , value : str ) -> list [tuple [str , int , str ]]:
114+ """Parse TransportCell entries from the NPC notes field."""
115+ result = []
116+ parsed = mwparserfromhell .parse (value )
117+ for template in parsed .ifilter_templates (recursive = True ):
118+ template_name = strip_code (template .name ).lower ().replace ("_" , " " )
119+ if template_name != "transportcell" :
120+ continue
121+ destination = strip_code (template .get (1 , "" ))
122+ price_str = strip_code (template .get (2 , "0" ))
123+ notes = strip_code (template .get (3 , "" ))
124+ try :
125+ price = int (price_str )
126+ except ValueError :
127+ price = 0
128+ result .append ((destination , price , notes ))
129+ return result
130+
107131 # endregion
0 commit comments