feat(py-monitor): add parse_price()
This commit is contained in:
1 parent
73139f4b4b
commit
0bea5057cc
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
|
||||
|
||||
|
||||
Reference in new issue
Block a user