Skip to content

Commit

Permalink
Fixed bug with extraneous character in some item descriptions, causin…
Browse files Browse the repository at this point in the history
…g auction to give a parsing error.
  • Loading branch information
Galarzaa90 committed Apr 19, 2021
1 parent a6c70d3 commit 04b8f7d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Changelog
Due to this library relying on external content, older versions are not guaranteed to work.
Try to always use the latest version.

.. v4.1.1
4.1.1 (2021-04-19)
==================
- Fixed bug with extraneous character in some item descriptions, causing auction to give a parsing error.

.. v4.1.0
4.1.0 (2021-03-30)
Expand Down
2 changes: 1 addition & 1 deletion tibiapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '4.1.0'
__version__ = '4.1.1'
__author__ = 'Allan Galarza'

import logging
Expand Down
2 changes: 1 addition & 1 deletion tibiapy/bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def _parse_image_box(cls, item_box):
description = None
name, *desc = title_text.split("\n")
if desc:
description = desc[0]
description = " ".join(desc)
m = id_regex.search(img_tag["src"])
if m:
item_id = int(m.group(1))
Expand Down
10 changes: 7 additions & 3 deletions tibiapy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ async def _fetch_all_pages(self, auction_id, paginator, item_type):
current_page = 2
while current_page <= paginator.total_pages:
content = await self._fetch_ajax_page(auction_id, item_type, current_page)
entries = AuctionDetails._parse_page_items(content, paginator.entry_class)
paginator.entries.extend(entries)
if content:
entries = AuctionDetails._parse_page_items(content, paginator.entry_class)
paginator.entries.extend(entries)
current_page += 1
paginator.fully_fetched = True

Expand All @@ -371,7 +372,10 @@ async def _fetch_ajax_page(self, auction_id, type_id, page):
f"type={type_id}&"
f"currentpage={page}",
headers=headers)
data = json.loads(page_response.content)
try:
data = json.loads(page_response.content.replace("\x0a", " "))
except json.decoder.JSONDecodeError:
return None
try:
return data['AjaxObjects'][0]['Data']
except KeyError:
Expand Down

0 comments on commit 04b8f7d

Please sign in to comment.