Skip to content

Commit fa63a92

Browse files
committed
Added flag to only parse auction's basic information
1 parent 5f7d012 commit fa63a92

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ 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+
3.4.0 (2020-09-19)
10+
=================
11+
12+
- Added option to only parsed the listed information of an auction, to skip the rest of the parsing.
13+
- Fixed wrong type hint in ``ListedAuction`` for ``status``.
14+
915
3.3.0 (2020-09-09)
1016
=================
1117

serve.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ async def get_auction(request: web.Request):
7777
fetch_items = int(request.query.get("fetch_items", 0))
7878
fetch_mounts = int(request.query.get("fetch_mounts", 0))
7979
fetch_outfits = int(request.query.get("fetch_outfits", 0))
80+
skip_details = int(request.query.get("skip_details", 0))
8081
boosted = await app["tibiapy"].fetch_auction(int(auction_id), fetch_items=fetch_items, fetch_mounts=fetch_mounts,
81-
fetch_outfits=fetch_outfits)
82+
fetch_outfits=fetch_outfits, skip_details=skip_details)
8283
return web.json_response(boosted, dumps=CustomJson.dumps)
8384

8485

tibiapy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from tibiapy.bazaar import *
1818
from tibiapy.client import *
1919

20-
__version__ = '3.3.0'
20+
__version__ = '3.4.0'
2121

2222
from logging import NullHandler
2323

tibiapy/bazaar.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def __init__(self, **kwargs):
645645
self.auction_end: datetime.datetime = kwargs.get("auction_end")
646646
self.bid: int = kwargs.get("bid", 0)
647647
self.bid_type: BidType = kwargs.get("bid_type")
648-
self.status: str = kwargs.get("status")
648+
self.status: AuctionStatus = kwargs.get("status")
649649

650650
def __repr__(self):
651651
return f"<{self.__class__.__name__} auction_id={self.auction_id} name={self.name} world={self.world}>"
@@ -960,7 +960,7 @@ def skills_map(self) -> Dict[str, 'SkillEntry']:
960960
return {skill.name: skill for skill in self.skills}
961961

962962
@classmethod
963-
def from_content(cls, content, auction_id=0):
963+
def from_content(cls, content, auction_id=0, skip_details=False):
964964
"""Parses an auction detail page from Tibia.com and extracts its data.
965965
966966
Parameters
@@ -971,6 +971,11 @@ def from_content(cls, content, auction_id=0):
971971
The ID of the auction.
972972
973973
It is not possible to extract the ID from the page's content, so it may be passed to assign it manually.
974+
skip_details: :class:`bool`, optional
975+
Whether to skip parsing the entire auction and only parse the information shown in lists. False by default.
976+
977+
This allows fetching basic information like name, level, vocation, world, bid and status, shaving off some
978+
parsing time.
974979
975980
Returns
976981
-------
@@ -990,6 +995,8 @@ def from_content(cls, content, auction_id=0):
990995
raise InvalidContent("content does not belong to a auction details page in Tibia.com")
991996
auction = cls._parse_auction(auction_row)
992997
auction.auction_id = auction_id
998+
if skip_details:
999+
return auction
9931000

9941001
details_tables = cls._parse_tables(parsed_content)
9951002
if "General" in details_tables:

tibiapy/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ async def fetch_auction_history(self, page=1):
267267
parsing_time = time.perf_counter() - start_time
268268
return TibiaResponse(response, auction_history, parsing_time)
269269

270-
async def fetch_auction(self, auction_id, *, fetch_items=False, fetch_mounts=False, fetch_outfits=False):
270+
async def fetch_auction(self, auction_id, *, fetch_items=False, fetch_mounts=False, fetch_outfits=False,
271+
skip_details=False):
271272
"""Fetches an auction by its ID.
272273
273274
.. versionadded:: 3.3.0
@@ -282,6 +283,11 @@ async def fetch_auction(self, auction_id, *, fetch_items=False, fetch_mounts=Fal
282283
Whether to fetch all of the character's mounts. By default only the first page is fetched.
283284
fetch_outfits: :class:`bool`
284285
Whether to fetch all of the character's outfits. By default only the first page is fetched.
286+
skip_details: :class:`bool`, optional
287+
Whether to skip parsing the entire auction and only parse the information shown in lists. False by default.
288+
289+
This allows fetching basic information like name, level, vocation, world, bid and status, shaving off some
290+
parsing time.
285291
286292
Returns
287293
-------
@@ -298,9 +304,9 @@ async def fetch_auction(self, auction_id, *, fetch_items=False, fetch_mounts=Fal
298304
"""
299305
response = await self._request("GET", AuctionDetails.get_url(auction_id))
300306
start_time = time.perf_counter()
301-
auction = AuctionDetails.from_content(response.content, auction_id)
307+
auction = AuctionDetails.from_content(response.content, auction_id, skip_details)
302308
parsing_time = time.perf_counter() - start_time
303-
if auction:
309+
if auction and not skip_details:
304310
if fetch_items:
305311
await self._fetch_all_pages(auction_id, auction.items, 0)
306312
await self._fetch_all_pages(auction_id, auction.store_items, 1)

0 commit comments

Comments
 (0)