feat(py-monitor): add parse_price()

This commit is contained in:
hoelee committed 2026-10-09 10:05:00 +08:00
1 parent 573ff387e9
commit 60db5f9436
1 file changed
+28
@@ -0,0 +1,28 @@
"""Price and condition parsing."""
import re
CONDITIONS = ["Brand new", "Like new", "Lightly used", "Well used", "Heavily used", "Used"]
CONDITION_MAP = {
"brand new": "Brand new",
"new": "Brand new",
"like new": "Like new",
"lightly used": "Lightly used",
"well used": "Well used",
"heavily used": "Heavily used",
"used": "Used",
}
def parse_price(s):
if not s:
return None
t = re.sub(r"[^0-9.]", "", s)
if not t:
return None
try:
return round(float(t), 2)
except ValueError:
return None