|
| 1 | +import requests |
| 2 | +from bs4 import BeautifulSoup |
| 3 | +import time |
| 4 | +import smtplib |
| 5 | + |
| 6 | +# header = { |
| 7 | +# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" |
| 8 | +# } |
| 9 | + |
| 10 | +# Url = "https://www.amazon.in/Apple-AirPods-Wireless-Charging-Case/dp/B07QDRYVCZ/ref=sr_1_1_sspa?crid=2O0YQXVBL4T86&dchild=1&keywords=airpods&qid=1601031081&sprefix=airpod%2Caps%2C615&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUFPVUpPNUNIQUE1RUUmZW5jcnlwdGVkSWQ9QTAxNzI3NjJPNlg3OTJFSTVSOE8mZW5jcnlwdGVkQWRJZD1BMDg1MTYzNjJSRUw4VFVKQzQ1TDkmd2lkZ2V0TmFtZT1zcF9hdGYmYWN0aW9uPWNsaWNrUmVkaXJlY3QmZG9Ob3RMb2dDbGljaz10cnVl" |
| 11 | + |
| 12 | +# get your browser information by searching "my user agent" |
| 13 | +user_agent = input("Enter your User-Agent string here\n") |
| 14 | +headers = { |
| 15 | + "User-Agent": f'{user_agent}' |
| 16 | + |
| 17 | +} |
| 18 | +Url = input("Drop the Url of product you wish to buy...!\n") |
| 19 | + |
| 20 | +page = requests.get(Url, headers=headers) |
| 21 | +soup = BeautifulSoup(page.content, "html.parser") |
| 22 | + |
| 23 | + |
| 24 | +# print(soup) |
| 25 | + |
| 26 | + |
| 27 | +def mail_sending(mail_id, title, password): |
| 28 | + server_mail = "smtp.gmail.com" |
| 29 | + port = 587 |
| 30 | + server = smtplib.SMTP(server_mail, port) |
| 31 | + server.ehlo() |
| 32 | + server.starttls() |
| 33 | + server.login(mail_id, password) |
| 34 | + subject = "GO BUY FAST!" |
| 35 | + body = f"Price of {title} is fallen below the threshold amount. Click on the link below to buy the product!!!\n\n" + Url |
| 36 | + message = f'Subject:{subject}\n\n {body}' |
| 37 | + server.sendmail(mail_id, mail_id, message) |
| 38 | + server.quit() |
| 39 | + |
| 40 | + |
| 41 | +def check_price(): |
| 42 | + title = soup.find(id="productTitle").get_text().strip() |
| 43 | + try: |
| 44 | + price = soup.find(id="priceblock_ourprice_row").get_text().strip()[:20].replace('₹', '').replace(' ', |
| 45 | + '').replace( |
| 46 | + 'Price:', '').replace('\n', '').replace('\xa0', '').replace(',', '').replace('Fu', '') |
| 47 | + |
| 48 | + except: |
| 49 | + try: |
| 50 | + price = soup.find(id="priceblock_dealprice").get_text().strip()[:20].replace('₹', '').replace(' ', |
| 51 | + '').replace( |
| 52 | + 'Price:', '').replace('\n', '').replace('\xa0', '').replace(',', '').replace('Fu', '') |
| 53 | + |
| 54 | + except: |
| 55 | + try: |
| 56 | + price = soup.find(id="priceblock_ourprice").get_text().strip()[:20].replace('₹', '').replace(' ', |
| 57 | + '').replace( |
| 58 | + 'Price:', '').replace('\n', '').replace('\xa0', '').replace(',', '').replace('Fu', '') |
| 59 | + |
| 60 | + except: |
| 61 | + price = soup.find(id="priceblock_ourprice_lbl").get_text().strip()[:20].replace('₹', '').replace(' ', |
| 62 | + '').replace( |
| 63 | + 'Price:', '').replace('\n', '').replace('\xa0', '').replace(',', '').replace('Fu', '') |
| 64 | + |
| 65 | + fixed_price = float(price) |
| 66 | + print(title) |
| 67 | + print(f'The current price is {fixed_price}') |
| 68 | + y_price = (input('Enter the price you wish to get the product at:')) |
| 69 | + your_price = y_price.replace(',', '') |
| 70 | + mail_id = input("Please enter your email id: ") |
| 71 | + password = input("Enter your app password here: ") |
| 72 | + print("Thank You! You'll receive an email as soon as the price of product drops...!") |
| 73 | + # print(price) |
| 74 | + if fixed_price <= float(your_price): |
| 75 | + mail_sending(mail_id, title, password) |
| 76 | + exit() |
| 77 | + else: |
| 78 | + pass |
| 79 | + |
| 80 | + |
| 81 | +while 1: |
| 82 | + check_price() |
| 83 | + # checks at an interval of 2 hours |
| 84 | + time.sleep(7200.00) |
0 commit comments