samedi 30 novembre 2019

How to keep python script keep running indefinitely

I made a GUI app from Tkinter in python and want to make such that after a specific time the program runs again and prints accordingly.

def check_price():
    name = entry_1.get()
    p = entry_2.get()
    ex_price = float(p)
    usr_email = entry_3.get()
    client_response = Client(name)
    source = client_response.html
    soup = BeautifulSoup(source, 'html.parser')
    try:
        title=soup.find('span', id ='productTitle').get_text().strip()
        label_4 = Label(root, text=title)
        label_4.grid(row=4, column=0)
    except AttributeError:
        title = "Wrong URL"
        label_4 = Label(root, text=title)
        label_4.grid(row=4, column=0)
        exit()
    try:
        price = soup.find('span', id ='priceblock_dealprice').get_text().strip()
        x="The item is currently discounted at : "+price
        label_5 = Label(root, text=x)
        label_5.grid(row=5, column=0)
    except AttributeError:
        try:
            price = soup.find('span', id ='priceblock_ourprice').get_text().strip()
            x = "The product is not discounted currently and Currently the price is : "+price
            label_5 = Label(root, text=x)
            label_5.grid(row=5, column=0)
        except AttributeError:
            x = "Product Unavailable!!"
            label_5 = Label(root, text=x)
            label_5.grid(row=5, column=0)
            exit()
    px = ""
    for ch in price:
        if(ch.isdigit()):
            px=px+ch
    converted_price=float(px)
    converted_price=converted_price/100
    if(converted_price < ex_price):
        send_mail(name, usr_email)
    else: 
        x = "The price is not currently below the price at which you would like to buy"
        label_6 = Label(root, text=x)
        label_6.grid(row=6, column=0)
        self.after(10, self.check_price)

So I want that function check_price be called again after 1 hour how can I do so? I used self.after but it is not working.




Aucun commentaire:

Enregistrer un commentaire