wishlist
wishlist copied to clipboard
marketplace_price property does not convert full number to float
For instance: Market Place price is $26.20 the property for marketplace_price returns 6.2
re.match in function only returns one instance of the digit preceding the decimal:
In [66]: test_string = "hello $26.20"
In [67]: match = re.match(".+(\d+\.\d+)", test_string)
In [68]: match.group(0)
Out[68]: 'hello $26.20'
In [69]: match.group(1)
Out[69]: '6.20'
regex being a horror from beyond the stars that mortal minds cannot safely contemplate, I could not find a fix that worked in match.group(). I can get more digits by adding \d before the decimal, but that only works for cases where the extra digit exists.
re.findall, however, seems to work without the grouping:
In [71]: proposed_fix = re.findall("\d+\.\d+", test_string)
In [72]: proposed_fix
Out[72]: ['26.20']
I would propose the following:
161 @property
162 def marketplace_price(self):
163 price = 0.0
164 el = self.soup.find("span", {"class": "itemUsedAndNewPrice"})
165 if el and len(el.contents) > 0:
166 match = re.findall("\d+\.\d+", el.contents[0])
167 price = float(match[0]) if match else 0.0
168 return price
May I make a pull request for this?
Absolutely, pull request away!