Siddharth2603

Untitled

Jan 4th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. import requests
  2. import bs4
  3. from bs4 import BeautifulSoup
  4. import smtplib
  5.  
  6. global url
  7. #url = "https://www.amazon.in/BassHeads-162-Secure-Braided-Earphones/dp/B07KXR889N/ref=sr_1_10?crid=URVJNBQLGUQY&keywords=boat+earphones+with+mic+and+bass&qid=1577558308&sprefix=boat+ea%2Caps%2C357&sr=8-10"
  8. global ant
  9. def main(url):
  10.     #url = "https://www.amazon.in/BassHeads-162-Secure-Braided-Earphones/dp/B07KXR889N/ref=sr_1_10?crid=URVJNBQLGUQY&keywords=boat+earphones+with+mic+and+bass&qid=1577558308&sprefix=boat+ea%2Caps%2C357&sr=8-10"
  11.     #url = input("Enter the url for your desired product")
  12.  
  13.     params = {
  14.         "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
  15.     }
  16.     r = requests.get(url, headers = params)
  17.     print(r.content)
  18.     soup = BeautifulSoup(r.content , features = "html5lib")
  19.     #print(soup)
  20.     price = soup.find(id = "priceblock_ourprice")
  21.     print(price)
  22.     p = price.text[2:]
  23.     global a
  24.     a = float(p)
  25.     print(a)
  26.     #wanted_price = 200
  27. global email
  28. def sendmail(email):
  29.     server = smtplib.SMTP("smtp.gmail.com", 587)
  30.     server.ehlo()
  31.     server.starttls()
  32.     server.ehlo()
  33.     server.login("tg3567.sc@gmail.com","candyeqdfldmyjao")
  34.     subject = "Prices Dropped"
  35.     body = "The price for your desired product has been dropped!!! \n"
  36.     msg = "Subject:\n {}\n{} : ".format(subject,body)
  37.     server.sendmail("tg3567.sc@gmail.com","sidchaturvedi.2000@gmail.com",msg)
  38.     server.quit()
  39. def final(email,price):
  40.     mail = email
  41.     #wanted_price = 200
  42.     if price < a:
  43.         sendmail(mail)
  44.         print("Email sent Succesfully")
  45. #main()
  46. #final("sidchaturvedi.2000@gmail.com",300 )
Add Comment
Please, Sign In to add comment