Amazing-Python-Scripts
82 строки · 2.6 Кб
1import requests2from bs4 import BeautifulSoup3import time4import smtplib5import pywhatkit6import datetime7
8# header = {
9# "
10# Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
11# "
12# }
13
14# Url = "
15# https://www.amazon.in/Apple-Original-MMTN2ZM-Lightning-Connector/dp/B01M1EEPOB/ref=sr_1_1?crid=XFITOYOGI999&keywords=airpods+apple&qid=1685422019&s=electronics&sprefix=airpods+appl%2Celectronics%2C458&sr=1-1
16# "
17
18# get your browser information by searching "my user agent"
19user_agent = input("Enter your User-Agent string here\n")20headers = {"User-Agent": f'{user_agent}'}21Url = input("Drop the Url of product you wish to buy...!\n")22
23page = requests.get(Url, headers=headers)24soup = BeautifulSoup(page.content, "html.parser")25
26# print(soup)
27
28
29def message_sending(phone_number, title):30now = datetime.datetime.now()31message = f"Price of {title} is fallen below the threshold amount. Click on the link below to buy the product!!!\n\n"32pywhatkit.sendwhatmsg(phone_number, message, now.hour, now.minute + 1)33
34
35def mail_sending(mail_id, title, password):36server_mail = "smtp.gmail.com"37port = 58738server = smtplib.SMTP(server_mail, port)39server.ehlo()40server.starttls()41server.login(mail_id, password)42subject = "GO BUY FAST!"43body = f"Price of {title} is fallen below the threshold amount. Click on the link below to buy the product!!!\n\n" + Url44message = f'Subject:{subject}\n\n {body}'45server.sendmail(mail_id, mail_id, message)46server.quit()47
48
49def check_price():50title = soup.find(id="productTitle").get_text().strip()51try:52price = price = soup.find('span', class_='a-price-whole').text53price = price[:len(price)-1]54
55except:56print("Object out of stock or removed")57return58
59fixed_price = float(price.replace(",", ""))60print(title)61print(f'The current price is {fixed_price}')62y_price = (input('Enter the price you wish to get the product at:'))63your_price = y_price.replace(',', '')64mail_id = input("Please enter your email id: ")65password = input("Enter your app password here: ")66phone_number = input("Please enter your phone number: ")67print(68"Thank You! You'll receive an email as soon as the price of product drops...!"69)70# print(price)71if fixed_price <= float(your_price):72mail_sending(mail_id, title, password)73message_sending(phone_number, title)74exit()75else:76pass77
78
79while 1:80check_price()81# checks at an interval of 2 hours82time.sleep(7200.00)83