Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. def convertPriceIntoFloat ( myString ):
  2. myString = myString.strip()
  3.  
  4. # 1.298,90 €
  5. if "€" in myString and "." in myString and "," in myString:
  6. myString = (myString.replace('€', '')).strip()
  7. myString = (myString.replace('.', '')).strip()
  8. float_price = float(myString.replace(',', '.'))
  9. return(float_price)
  10. if "€" in myString and "*" in myString and "ab" in myString:
  11. myString = (myString.replace('€', '')).strip()
  12. myString = (myString.replace('*', '')).strip()
  13. myString = (myString.replace('ab', '')).strip()
  14. float_price = float(myString.replace(',', '.'))
  15. return(float_price)
  16. if "€" in myString and "ab" in myString:
  17. myString = (myString.replace('€', '')).strip()
  18. myString = (myString.replace('ab', '')).strip()
  19. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  20. # thousand EURO or more
  21. myString = (myString.replace('.', '')).strip()
  22. float_price = float(myString.replace(',', '.'))
  23. else:
  24. float_price = float(myString.replace(',', '.'))
  25. return(float_price)
  26.  
  27. # 599,- €
  28. if ",-" in myString and "€" in myString:
  29. myString = (myString.replace('€', '')).strip()
  30. myString = (myString.replace(',-', '.00')).strip()
  31. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  32. # thousand EURO or more
  33. myString = (myString.replace('.', '')).strip()
  34. float_price = float(myString.replace(',', '.'))
  35. else:
  36. float_price = float(myString.replace(',', '.'))
  37. return(float_price)
  38.  
  39. # ↵179,89 €↵*↵
  40. if "€" in myString and "*" in myString:
  41. myString = (myString.replace('€', '')).strip()
  42. myString = (myString.replace('*', '')).strip()
  43. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  44. # thousand EURO or more
  45. myString = (myString.replace('.', '')).strip()
  46. float_price = float(myString.replace(',', '.'))
  47. else:
  48. float_price = float(myString.replace(',', '.'))
  49. return(float_price)
  50.  
  51. # ab 223,90 EUR
  52. if "EUR" in myString and "ab" in myString:
  53. myString = (myString.replace('EUR', '')).strip()
  54. myString = (myString.replace('ab', '')).strip()
  55. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  56. # thousand EURO or more
  57. myString = (myString.replace('.', '')).strip()
  58. float_price = float(myString.replace(',', '.'))
  59. else:
  60. float_price = float(myString.replace(',', '.'))
  61. return(float_price)
  62.  
  63. if "EUR" in myString:
  64. # GB Pound
  65. myString = (myString.replace('EUR', '')).strip()
  66. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  67. # thousand EURO or more
  68. myString = (myString.replace('.', '')).strip()
  69. float_price = float(myString.replace(',', '.'))
  70. else:
  71. float_price = float(myString.replace(',', '.'))
  72. return(float_price)
  73.  
  74. if "CHF" in myString:
  75. # CHF Schweiz
  76. myString = (myString.replace('CHF', '')).strip()
  77. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  78. # thousand Franks or more
  79. myString = (myString.replace('.', '')).strip()
  80. float_price = float(myString.replace(',', '.'))
  81. else:
  82. float_price = float(myString.replace(',', '.'))
  83. return(float_price)
  84.  
  85. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  86. # thousand EURO or more, coming in as a float already
  87. myString = (myString.replace('.', '')).strip()
  88. float_price = float(myString.replace(',', '.'))
  89. return(float_price)
  90.  
  91. # 122,60 £
  92. if "£" in myString:
  93. # remove GB Pound sign
  94. myString = (myString.replace('£', '')).strip()
  95.  
  96. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  97. # thousand GB Pounds or more
  98. myString = (myString.replace('.', '')).strip()
  99. float_price = float(myString.replace(',', '.'))
  100. # 122,60 £
  101. if re.match('^d{1,3},d{2}$', myString) is not None:
  102. #
  103. myString = (myString.replace('.', '')).strip()
  104. float_price = float(myString.replace(',', '.'))
  105. return(float_price)
  106. if "$" in myString:
  107. # GB Pound
  108. myString = (myString.replace('$', '')).strip()
  109. float_price = float(myString.replace(',', ''))
  110. return(float_price)
  111. if ",-" in myString:
  112. float_price = float(myString.replace(',-', '.00'))
  113. return(float_price)
  114. if re.match('^d{1,3},d{2}$', myString) is not None:
  115. float_price = float(myString.replace(',', '.'))
  116. return(float_price)
  117. if " " in myString and "&#8364" in myString:
  118. return ( getPriceFromCommaString ( myString ) )
  119. # UVP: 44,95 EURO
  120. if "UVP:" in myString and "EURO" in myString:
  121. myString = (myString.replace('UVP:', '')).strip()
  122. myString = (myString.replace('EURO', '')).strip()
  123. float_price = float(myString.replace(',', '.'))
  124. return(float_price)
  125. # 22,99 €
  126. # € 1.199,99
  127. if "€" in myString:
  128. myString = (myString.replace('€', '')).strip()
  129. if re.match('^d{1,3}.d{3},d{2}$', myString) is not None:
  130. # thousand EURO or more
  131. myString = (myString.replace('.', '')).strip()
  132. float_price = float(myString.replace(',', '.'))
  133. else:
  134. float_price = float(myString.replace(',', '.'))
  135. return(float_price)
  136. else:
  137. return(myString)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement