Skip to content

Commit 78ec014

Browse files
committed
Added missing docstrings
1 parent a43da02 commit 78ec014

File tree

1 file changed

+134
-11
lines changed

1 file changed

+134
-11
lines changed

tibiapy/bazaar.py

Lines changed: 134 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import urllib.parse
44
from abc import abstractmethod
55

6-
from typing import Dict, List, Optional
6+
from typing import Dict, List, Optional, Type
7+
8+
import bs4
79

810
from tibiapy import abc, InvalidContent, Sex, Vocation
911
from tibiapy.abc import BaseCharacter
@@ -680,6 +682,20 @@ def get_url(cls, auction_id):
680682

681683
@classmethod
682684
def _parse_auction(cls, auction_row, auction_id=0):
685+
"""Parses an auction's table, extracting its data.
686+
687+
Parameters
688+
----------
689+
auction_row: :class:`bs4.Tag`
690+
The row containing the auction's information.
691+
auction_id: :class:`int`
692+
The ID of the auction.
693+
694+
Returns
695+
-------
696+
:class:`ListedAuction`
697+
The auction contained in the table.
698+
"""
683699
header_container = auction_row.find("div", attrs={"class": "AuctionHeader"})
684700
char_name_container = header_container.find("div", attrs={"class": "AuctionCharacterName"})
685701
char_link = char_name_container.find("a")
@@ -933,6 +949,7 @@ def skills_map(self) -> Dict[str, 'SkillEntry']:
933949

934950
@property
935951
def completed_bestiary_entries(self):
952+
""":class:`list` of :class:`BestiaryEntry`: Gets a list of completed bestiary entries."""
936953
return [e for e in self.bestiary_progress if e.completed]
937954

938955
@classmethod
@@ -985,39 +1002,53 @@ def from_content(cls, content, auction_id=0):
9851002
if "Blessings" in details_tables:
9861003
auction._parse_blessings_table(details_tables["Blessings"])
9871004
if "Imbuements" in details_tables:
988-
auction.imbuements = cls._parse_single_row_table(details_tables["Imbuements"])
1005+
auction.imbuements = cls._parse_single_column_table(details_tables["Imbuements"])
9891006
if "Charms" in details_tables:
9901007
auction._parse_charms_table(details_tables["Charms"])
9911008
if "CompletedCyclopediaMapAreas" in details_tables:
992-
auction.completed_cyclopedia_map_areas = cls._parse_single_row_table(
1009+
auction.completed_cyclopedia_map_areas = cls._parse_single_column_table(
9931010
details_tables["CompletedCyclopediaMapAreas"])
9941011
if "CompletedQuestLines" in details_tables:
995-
auction.completed_quest_lines = cls._parse_single_row_table(details_tables["CompletedQuestLines"])
1012+
auction.completed_quest_lines = cls._parse_single_column_table(details_tables["CompletedQuestLines"])
9961013
if "Titles" in details_tables:
997-
auction.titles = cls._parse_single_row_table(details_tables["Titles"])
1014+
auction.titles = cls._parse_single_column_table(details_tables["Titles"])
9981015
if "Achievements" in details_tables:
9991016
auction._parse_achievements_table(details_tables["Achievements"])
10001017
if "BestiaryProgress" in details_tables:
10011018
auction._parse_bestiary_table(details_tables["BestiaryProgress"])
10021019
return auction
10031020

10041021
@classmethod
1005-
def _parse_tables(cls, parsed_content):
1006-
"""Parses c
1022+
def _parse_tables(cls, parsed_content) -> Dict[str, bs4.Tag]:
1023+
"""Parses the character details tables.
10071024
10081025
Parameters
10091026
----------
1010-
parsed_content
1027+
parsed_content: :class:`bs4.Tag'
1028+
The parsed content of the auction.
10111029
10121030
Returns
10131031
-------
1014-
1032+
:class:`dict`
1033+
A dictionary of the tables, grouped by their id.
10151034
"""
10161035
details_tables = parsed_content.find_all("div", {"class": "CharacterDetailsBlock"})
10171036
return {table["id"]: table for table in details_tables}
10181037

10191038
@classmethod
1020-
def _parse_data_table(cls, table):
1039+
def _parse_data_table(cls, table) -> Dict[str, str]:
1040+
"""Parses a simple data table into a key value mapping.
1041+
1042+
Parameters
1043+
----------
1044+
table: :class:`bs4.Tag`
1045+
The table to be parsed.
1046+
1047+
Returns
1048+
-------
1049+
:class:`dict`
1050+
A mapping containing the table's data.
1051+
"""
10211052
rows = table.find_all("tr")
10221053
data = {}
10231054
for row in rows:
@@ -1028,6 +1059,13 @@ def _parse_data_table(cls, table):
10281059
return data
10291060

10301061
def parse_skills_table(self, table):
1062+
"""Parses the skills table.
1063+
1064+
Parameters
1065+
----------
1066+
table: :class:`bs4.Tag`
1067+
The table containing the character's skill.
1068+
"""
10311069
rows = table.find_all("tr")
10321070
skills = []
10331071
for row in rows:
@@ -1039,6 +1077,13 @@ def parse_skills_table(self, table):
10391077
self.skills = skills
10401078

10411079
def _parse_blessings_table(self, table):
1080+
"""Parses the blessings table.
1081+
1082+
Parameters
1083+
----------
1084+
table: :class:`bs4.Tag`
1085+
The table containing the character's blessings.
1086+
"""
10421087
table_content = table.find("table", attrs={"class": "TableContent"})
10431088
_, *rows = table_content.find_all("tr")
10441089
for row in rows:
@@ -1048,7 +1093,19 @@ def _parse_blessings_table(self, table):
10481093
self.blessings.append(BlessingEntry(name_c, amount))
10491094

10501095
@classmethod
1051-
def _parse_single_row_table(cls, table):
1096+
def _parse_single_column_table(cls, table):
1097+
"""Parses a table with a single column into an array.
1098+
1099+
Parameters
1100+
----------
1101+
table: :class:`bs4.Tag`
1102+
A table with a single column.
1103+
1104+
Returns
1105+
-------
1106+
:class:`list` of :class:`str`
1107+
A list with the contents of each row.
1108+
"""
10521109
table_content = table.find_all("table", attrs={"class": "TableContent"})[-1]
10531110
_, *rows = table_content.find_all("tr")
10541111
ret = []
@@ -1061,6 +1118,13 @@ def _parse_single_row_table(cls, table):
10611118
return ret
10621119

10631120
def _parse_charms_table(self, table):
1121+
"""Parses the charms table and extracts its information.
1122+
1123+
Parameters
1124+
----------
1125+
table: :class:`bs4.Tag`
1126+
The table containing the charms.
1127+
"""
10641128
table_content = table.find("table", attrs={"class": "TableContent"})
10651129
_, *rows = table_content.find_all("tr")
10661130
for row in rows:
@@ -1070,6 +1134,13 @@ def _parse_charms_table(self, table):
10701134
self.charms.append(CharmEntry(name_c, cost))
10711135

10721136
def _parse_achievements_table(self, table):
1137+
"""Parses the achievements table and extracts its information.
1138+
1139+
Parameters
1140+
----------
1141+
table: :class:`bs4.Tag`
1142+
The table containing the achievements.
1143+
"""
10731144
table_content = table.find("table", attrs={"class": "TableContent"})
10741145
_, *rows = table_content.find_all("tr")
10751146
for row in rows:
@@ -1081,6 +1152,13 @@ def _parse_achievements_table(self, table):
10811152
self.achievements.append(AchievementEntry(text, secret))
10821153

10831154
def _parse_bestiary_table(self, table):
1155+
"""Parses the bestiary table and extracts its information.
1156+
1157+
Parameters
1158+
----------
1159+
table: :class:`bs4.Tag`
1160+
The table containing the bestiary information.
1161+
"""
10841162
table_content = table.find("table", attrs={"class": "TableContent"})
10851163
_, *rows = table_content.find_all("tr")
10861164
for row in rows:
@@ -1094,6 +1172,20 @@ def _parse_bestiary_table(self, table):
10941172

10951173
@classmethod
10961174
def parse_page_items(cls, content, entry_class):
1175+
"""Parses the elements of a page in the items, mounts and outfits.
1176+
1177+
Attributes
1178+
----------
1179+
content: :class:`str`
1180+
The HTML content in the page.
1181+
entry_class:
1182+
The class defining the elements.
1183+
1184+
Returns
1185+
-------
1186+
-
1187+
The entries contained in the page.
1188+
"""
10971189
parsed_content = parse_tibiacom_content(content, builder='html5lib')
10981190
item_boxes = parsed_content.find_all("div", attrs={"class": "CVIcon"})
10991191
entries = []
@@ -1104,6 +1196,13 @@ def parse_page_items(cls, content, entry_class):
11041196
return entries
11051197

11061198
def _parse_general_table(self, table):
1199+
"""Parses the general information table and assigns its values.
1200+
1201+
Parameters
1202+
----------
1203+
table: :class:`bs4.Tag`
1204+
The table with general information.
1205+
"""
11071206
content_containers = table.find_all("table", {"class": "TableContent"})
11081207
general_stats = self._parse_data_table(content_containers[0])
11091208
self.hit_points = parse_integer(general_stats.get("hit_points", "0"))
@@ -1297,6 +1396,18 @@ def get_by_id(self, entry_id):
12971396

12981397
@classmethod
12991398
def _parse_table(cls, table):
1399+
"""Parses the item summary table.
1400+
1401+
Parameters
1402+
----------
1403+
table: :class:`bs4.Tag`
1404+
The table containing the item summary.
1405+
1406+
Returns
1407+
-------
1408+
:class:`ItemSummary`
1409+
The item summary contained in the table.
1410+
"""
13001411
summary = cls()
13011412
summary._parse_pagination(table)
13021413
item_boxes = table.find_all("div", attrs={"class": "CVIcon"})
@@ -1395,6 +1506,18 @@ def get_by_id(self, entry_id):
13951506

13961507
@classmethod
13971508
def _parse_table(cls, table):
1509+
"""Parses the outfits table.
1510+
1511+
Parameters
1512+
----------
1513+
table: :class:`bs4.Tag`
1514+
The table containing the character outfits.
1515+
1516+
Returns
1517+
-------
1518+
:class:`Outfits`
1519+
The outfits contained in the table.
1520+
"""
13981521
summary = cls()
13991522
summary._parse_pagination(table)
14001523
item_boxes = table.find_all("div", attrs={"class": "CVIcon"})

0 commit comments

Comments
 (0)