Features: 1) Add optional currency parameter to resolve_price_with_currency for enhanced flexibility;

Fixes: 1) Address minor spacing inconsistencies in list comprehension and JSON detection logic;

Extra: 1) Update `.gitignore` to exclude `.astro/` directory.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-06-17 15:39:37 +03:00
parent b105561c10
commit 6ce7b7a6f9
2 changed files with 8 additions and 5 deletions

3
.gitignore vendored
View file

@ -64,6 +64,9 @@ htmlcov/
.cover .cover
.pybuilder/ .pybuilder/
# Astro
.astro/
# Celery # Celery
celerybeat-schedule celerybeat-schedule
celerybeat.pid celerybeat.pid

View file

@ -37,7 +37,7 @@ class AbstractVendor:
if total == 0: if total == 0:
return [] return []
chunk_size = max(1, (total + num_chunks - 1) // num_chunks) chunk_size = max(1, (total + num_chunks - 1) // num_chunks)
return [data[i : i + chunk_size] for i in range(0, total, chunk_size)] return [data[i: i + chunk_size] for i in range(0, total, chunk_size)]
@staticmethod @staticmethod
def auto_convert_value(value): def auto_convert_value(value):
@ -85,7 +85,7 @@ class AbstractVendor:
# Try to detect a JSON object or array. # Try to detect a JSON object or array.
stripped_value = value.strip() stripped_value = value.strip()
if (stripped_value.startswith("{") and stripped_value.endswith("}")) or ( if (stripped_value.startswith("{") and stripped_value.endswith("}")) or (
stripped_value.startswith("[") and stripped_value.endswith("]") stripped_value.startswith("[") and stripped_value.endswith("]")
): ):
with suppress(Exception): with suppress(Exception):
parsed = json.loads(value) parsed = json.loads(value)
@ -162,13 +162,13 @@ class AbstractVendor:
return round(price, 2) return round(price, 2)
def resolve_price_with_currency(self, price, provider): def resolve_price_with_currency(self, price, provider, currency=None):
rates = get_rates(provider) rates = get_rates(provider)
rate = rates.get(self.currency) rate = rates.get(currency or self.currency)
if not rate: if not rate:
raise RatesError(f"No rate found for {self.currency} in {rates} with probider {provider}...") raise RatesError(f"No rate found for {currency or self.currency} in {rates} with probider {provider}...")
return round(price / rate, 2) if rate else round(price, 2) return round(price / rate, 2) if rate else round(price, 2)