Skip to content

Commit

Permalink
fix bug where listing count occasionally fails to register - bump ver…
Browse files Browse the repository at this point in the history
…sion from 0.2.12 --> 0.2.13
  • Loading branch information
irahorecka committed Aug 25, 2024
1 parent faa9be2 commit 6450cc2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chrono24/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Import chrono24 and use chrono24.query to interface Chrono24
from chrono24.api import Chrono24 as query

__version__ = "0.2.12"
__version__ = "0.2.13"
5 changes: 3 additions & 2 deletions chrono24/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ def _get_listings_with_attempts(listings_url, max_attempts=5):
while attempts < max_attempts:
try:
listings = Listings(get_html(listings_url))
# Return Listings instance if no AttributeError is raised
# Return Listings instance if no AttributeError or KeyError is raised
next(listings.htmls) # Check if listings are found
return listings
except AttributeError:
except (AttributeError, KeyError):
attempts += 1
print(f"Retrying HTML parsing... Attempt # {attempts}.")
time.sleep(1) # Wait 1 second before retrying
Expand Down Expand Up @@ -253,6 +253,7 @@ def _get_total_count(html):
metadata_json_str = match[1]
metadata = json.loads(metadata_json_str)
# Only return total count if listings are found
# metadata["data"] sometimes does not contain "searchResult" key - throws KeyError
total_count = int(metadata["data"]["searchResult"]["numResult"])
if total_count > 0:
return total_count
Expand Down

0 comments on commit 6450cc2

Please sign in to comment.