Amazing-Python-Scripts

Форк
0
82 строки · 2.6 Кб
1
import requests
2
from bs4 import BeautifulSoup
3
import time
4
import smtplib
5
import pywhatkit
6
import datetime
7

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"
19
user_agent = input("Enter your User-Agent string here\n")
20
headers = {"User-Agent": f'{user_agent}'}
21
Url = input("Drop the Url of product you wish to buy...!\n")
22

23
page = requests.get(Url, headers=headers)
24
soup = BeautifulSoup(page.content, "html.parser")
25

26
# print(soup)
27

28

29
def message_sending(phone_number, title):
30
    now = datetime.datetime.now()
31
    message = f"Price of {title} is fallen below the threshold amount. Click on the link below to buy the product!!!\n\n"
32
    pywhatkit.sendwhatmsg(phone_number, message, now.hour, now.minute + 1)
33

34

35
def mail_sending(mail_id, title, password):
36
    server_mail = "smtp.gmail.com"
37
    port = 587
38
    server = smtplib.SMTP(server_mail, port)
39
    server.ehlo()
40
    server.starttls()
41
    server.login(mail_id, password)
42
    subject = "GO BUY FAST!"
43
    body = f"Price of {title} is fallen below the threshold amount. Click on the link below to buy the product!!!\n\n" + Url
44
    message = f'Subject:{subject}\n\n {body}'
45
    server.sendmail(mail_id, mail_id, message)
46
    server.quit()
47

48

49
def check_price():
50
    title = soup.find(id="productTitle").get_text().strip()
51
    try:
52
        price = price = soup.find('span', class_='a-price-whole').text
53
        price = price[:len(price)-1]
54

55
    except:
56
        print("Object out of stock or removed")
57
        return
58

59
    fixed_price = float(price.replace(",", ""))
60
    print(title)
61
    print(f'The current price is {fixed_price}')
62
    y_price = (input('Enter the price you wish to get the product at:'))
63
    your_price = y_price.replace(',', '')
64
    mail_id = input("Please enter your email id: ")
65
    password = input("Enter your app password here: ")
66
    phone_number = input("Please enter your phone number: ")
67
    print(
68
        "Thank You! You'll receive an email as soon as the price of product drops...!"
69
    )
70
    # print(price)
71
    if fixed_price <= float(your_price):
72
        mail_sending(mail_id, title, password)
73
        message_sending(phone_number, title)
74
        exit()
75
    else:
76
        pass
77

78

79
while 1:
80
    check_price()
81
    # checks at an interval of 2 hours
82
    time.sleep(7200.00)
83

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.