示例#1
0
#     message = client.messages.create(to=RECIPIENT_SMS, from_=SENDER_SMS, body=content)

# AUTHENTICATE
client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)

URL = "https://www.bestbuy.com/site/sony-playstation-5-digital-edition-console/6430161.p?skuId=6430161"
page = requests.get(URL, headers={"User-Agent": "Defined"})
soup = BeautifulSoup(page.content, "html.parser")
if soup.find(class_="btn btn-disabled btn-lg btn-block add-to-cart-button"
             ) is not None:
    if datetime.datetime.now().hour == 12:
        client = SendGridAPIClient(
            SENDGRID_API_KEY)  #> <class 'sendgrid.sendgrid.SendGridAPIClient>
        print("CLIENT:", type(client))
        subject = "PS5 Update"
        html_content = "The PS5 is still not available at Bestbuy"
        message = Mail(from_email=MY_ADDRESS,
                       to_emails=MY_ADDRESS,
                       subject=subject,
                       html_content=html_content)
        try:
            response = client.send(message)
        except Exception as e:
            print("OOPS", e.message)
else:
    # COMPILE REQUEST PARAMETERS (PREPARE THE MESSAGE)
    content = "Hello, the PS5 is available at BestBuy! https://www.bestbuy.com/site/sony-playstation-5-digital-edition-console/6430161.p?skuId=6430161"
    message = client.messages.create(to=RECIPIENT_SMS,
                                     from_=SENDER_SMS,
                                     body=content)