Skip to content

Commit 4ff2410

Browse files
committed
Speed up auctions fetching when skipping details
1 parent eaa6c61 commit 4ff2410

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ Changelog
66
Due to this library relying on external content, older versions are not guaranteed to work.
77
Try to always use the latest version.
88

9+
.. v3.5.4:
10+
11+
3.5.4 (2020-09-24)
12+
==================
13+
14+
- Fetching auctions while skipping details is now faster.
15+
- Fixed bug in tournaments parsing.
16+
917
.. v3.5.3:
1018
1119
3.5.3 (2020-09-24)

tests/tests_bazaar.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,31 @@ def test_auction_details_from_content_finished(self):
231231
self.assertEqual(509, len(auction.bestiary_progress))
232232
self.assertEqual(205, len(auction.completed_bestiary_entries))
233233

234+
def test_auction_details_from_content_finished_skip_details(self):
235+
auction = AuctionDetails.from_content(self.load_resource(FILE_AUCTION_FINISHED), skip_details=True)
236+
237+
self.assertIsNotNone(auction)
238+
239+
# Listing box
240+
self.assertEqual("Vireloz", auction.name)
241+
self.assertIn(auction.name, auction.character_url)
242+
self.assertIn(str(auction.auction_id), auction.url)
243+
self.assertEqual(1161, auction.level)
244+
self.assertEqual(Vocation.ROYAL_PALADIN, auction.vocation)
245+
self.assertEqual(Sex.MALE, auction.sex)
246+
self.assertEqual("Wintera", auction.world)
247+
self.assertIsNotNone(auction.outfit)
248+
self.assertEqual(1322, auction.outfit.outfit_id)
249+
self.assertEqual(4, len(auction.displayed_items))
250+
self.assertEqual("gnome armor", auction.displayed_items[0].name)
251+
self.assertEqual("falcon coif", auction.displayed_items[1].name)
252+
self.assertEqual("pair of soulstalkers", auction.displayed_items[2].name)
253+
self.assertEqual("lion spangenhelm", auction.displayed_items[3].name)
254+
255+
self.assertEqual(330000, auction.bid)
256+
self.assertEqual(BidType.MINIMUM, auction.bid_type)
257+
self.assertEqual(AuctionStatus.FINISHED, auction.status)
258+
234259
def test_auction_details_from_content_not_found(self):
235260
auction = AuctionDetails.from_content(self.load_resource(FILE_AUCTION_NOT_FOUND))
236261

tibiapy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '3.5.3'
1+
__version__ = '3.5.4'
22
__author__ = 'Allan Galarza'
33

44
import logging

tibiapy/bazaar.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import logging
23
import re
34
import urllib.parse
45
import warnings
@@ -46,6 +47,8 @@
4647
description_regex = re.compile(r'"(?:an?\s)?([^"]+)"')
4748
quotes = re.compile(r'"([^"]+)"')
4849

50+
log = logging.getLogger("tibiapy")
51+
4952

5053
class AchievementEntry(abc.Serializable):
5154
"""An unlocked achievement by the character.
@@ -1003,7 +1006,7 @@ def from_content(cls, content, auction_id=0, skip_details=False):
10031006
InvalidContent
10041007
If the content does not belong to a auction detail's page.
10051008
"""
1006-
parsed_content = parse_tibiacom_content(content, builder='html5lib')
1009+
parsed_content = parse_tibiacom_content(content, builder='html5lib' if not skip_details else 'lxml')
10071010
auction_row = parsed_content.find("div", attrs={"class": "Auction"})
10081011
if not auction_row:
10091012
if "internal error" in content:
@@ -1218,7 +1221,7 @@ def parse_page_items(cls, content, entry_class):
12181221
-
12191222
The entries contained in the page.
12201223
"""
1221-
parsed_content = parse_tibiacom_content(content, builder='html5lib')
1224+
parsed_content = parse_tibiacom_content(content, builder='lxml')
12221225
item_boxes = parsed_content.find_all("div", attrs={"class": "CVIcon"})
12231226
entries = []
12241227
for item_box in item_boxes:

tibiapy/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ async def _request(self, method, url, data=None, headers=None):
183183
await self._session_ready.wait()
184184
try:
185185
init_time = time.perf_counter()
186-
log.info(f"{url} | {method} | Fetching...")
186+
log.info(f"%s | %s | Fetching...", url, method)
187187
async with self.session.request(method, url, data=data, headers=headers) as resp:
188-
log.info(f"{url} | {method} | {resp.status} {resp.reason}")
188+
log.info(f"%s | %s | %s %s", url, method, resp.status, resp.reason)
189189
if "maintenance.tibia.com" in str(resp.url):
190190
raise SiteMaintenanceError("Tibia.com is down for maintenance.")
191191
self._handle_status(resp.status)

tibiapy/tournament.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def _parse_tournament_rules(self, table):
482482
for row in rows[1:]:
483483
cols_raw = row.find_all('td')
484484
cols = [ele.text.strip() for ele in cols_raw]
485-
field, value = cols
485+
field, value, *_ = cols
486486
field = field.replace("\xa0", "_").replace(" ", "_").replace(":", "").lower()
487487
value = value.replace("\xa0", " ")
488488
if field in bool_fields:

tibiapy/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def parse_tibiacom_content(content, *, html_class="BoxContent", tag="div", build
333333
The parsed content.
334334
"""
335335
strainer = bs4.SoupStrainer(tag, class_=html_class) if builder != "html5lib" else None
336-
return bs4.BeautifulSoup(content.replace('ISO-8859-1', 'utf-8'), builder, parse_only=strainer)
336+
return bs4.BeautifulSoup(content.replace('ISO-8859-1', 'utf-8', 1), builder, parse_only=strainer)
337337

338338

339339
T = TypeVar('T')

0 commit comments

Comments
 (0)