Skip to content

Commit b5e96c9

Browse files
committed
Compile PRICE_RE regex once at module level
1 parent 607f123 commit b5e96c9

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

price_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
2121
"Accept-Language": "en-US,en;q=0.9",
2222
}
23+
PRICE_RE = re.compile(r"\$([0-9,]+\.?[0-9]*)")
2324

2425

2526
class PriceService:
@@ -74,9 +75,7 @@ def _extract_price_after(self, html: str, prefix: str) -> Optional[float]:
7475
return None
7576

7677
after = html[pos : pos + 200]
77-
78-
# Find $ followed by number
79-
match = re.search(r"\$([0-9,]+\.?[0-9]*)", after)
78+
match = PRICE_RE.search(after)
8079
if match:
8180
price_str = match.group(1).replace(",", "")
8281
try:

0 commit comments

Comments
 (0)