I'm trying to build a web scraping script which sends me an email when the price of a certain product changes. I use an "old_price" variable and a "current_price" variable. if the current price does not equal the old price, an email should be sent to me and the old price should become the current price. The problem lays inside the if statement. The old_price variable does not get updated, so the old price will never match the current price, thus sending me a email every time even when the price hasen't changed.
def checkPrice():
old_price = 0.0
current_price = soup.find("div", class_="fund-price").get_text()
current_price = (current_price.lstrip("€"))
current_price = float(current_price[0:4])
print("old price is: ", old_price)
print("current price is: ", current_price)
if(current_price != old_price):
old_price = current_price
sendEmail()
while(True):
checkPrice()
time.sleep(3600)