Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def convertPriceIntoFloat ( myString ):
- myString = myString.strip()
- # 1.298,90 €
- if "€" in myString and "." in myString and "," in myString:
- myString = (myString.replace('€', '')).strip()
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- if "€" in myString and "*" in myString and "ab" in myString:
- myString = (myString.replace('€', '')).strip()
- myString = (myString.replace('*', '')).strip()
- myString = (myString.replace('ab', '')).strip()
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- if "€" in myString and "ab" in myString:
- myString = (myString.replace('€', '')).strip()
- myString = (myString.replace('ab', '')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand EURO or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- else:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- # 599,- €
- if ",-" in myString and "€" in myString:
- myString = (myString.replace('€', '')).strip()
- myString = (myString.replace(',-', '.00')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand EURO or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- else:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- # ↵179,89 €↵*↵
- if "€" in myString and "*" in myString:
- myString = (myString.replace('€', '')).strip()
- myString = (myString.replace('*', '')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand EURO or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- else:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- # ab 223,90 EUR
- if "EUR" in myString and "ab" in myString:
- myString = (myString.replace('EUR', '')).strip()
- myString = (myString.replace('ab', '')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand EURO or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- else:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- if "EUR" in myString:
- # GB Pound
- myString = (myString.replace('EUR', '')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand EURO or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- else:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- if "CHF" in myString:
- # CHF Schweiz
- myString = (myString.replace('CHF', '')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand Franks or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- else:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand EURO or more, coming in as a float already
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- # 122,60 £
- if "£" in myString:
- # remove GB Pound sign
- myString = (myString.replace('£', '')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand GB Pounds or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- # 122,60 £
- if re.match('^d{1,3},d{2}$', myString) is not None:
- #
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- if "$" in myString:
- # GB Pound
- myString = (myString.replace('$', '')).strip()
- float_price = float(myString.replace(',', ''))
- return(float_price)
- if ",-" in myString:
- float_price = float(myString.replace(',-', '.00'))
- return(float_price)
- if re.match('^d{1,3},d{2}$', myString) is not None:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- if " " in myString and "€" in myString:
- return ( getPriceFromCommaString ( myString ) )
- # UVP: 44,95 EURO
- if "UVP:" in myString and "EURO" in myString:
- myString = (myString.replace('UVP:', '')).strip()
- myString = (myString.replace('EURO', '')).strip()
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- # 22,99 €
- # € 1.199,99
- if "€" in myString:
- myString = (myString.replace('€', '')).strip()
- if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
- # thousand EURO or more
- myString = (myString.replace('.', '')).strip()
- float_price = float(myString.replace(',', '.'))
- else:
- float_price = float(myString.replace(',', '.'))
- return(float_price)
- else:
- return(myString)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement