Skip to content

Commit

Permalink
Validate ASIN format
Browse files Browse the repository at this point in the history
  • Loading branch information
leonghui committed Feb 3, 2024
1 parent fd58018 commit 14aa03c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion amazon_feed_data.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from dataclasses import dataclass, field
from enum import Enum
from logging import Logger
import re

from requests_cache import CachedSession


ASIN_PATTERN = r"^(B[\dA-Z]{9}|\d{9}(X|\d))$"


class UnavailabilityText(str, Enum): # allow comparison with strings
EN = "Currently unavailable."

Expand Down Expand Up @@ -142,7 +146,7 @@ class AmazonItemQuery(_BaseQueryWithPriceFilter):
query_str: str = "B08166SLDF" # AMD Ryzen 5 5600X Processor

def __post_init__(self):
if not isinstance(self.query_str, str):
if not re.match(ASIN_PATTERN, self.query_str):
self.status.errors.append("Invalid id (ASIN)")

self.validate_country()
Expand Down

0 comments on commit 14aa03c

Please sign in to comment.