Skip to content

Instantly share code, notes, and snippets.

@sequoiap
Created May 3, 2023 15:57
Show Gist options
  • Save sequoiap/d1c9e7f0a0026fc4d6de8b1e182a48bf to your computer and use it in GitHub Desktop.
Save sequoiap/d1c9e7f0a0026fc4d6de8b1e182a48bf to your computer and use it in GitHub Desktop.
Variations on a script I used with a cron job to see if a laptop was on sale yet.
import os
import sys
import requests
from bs4 import BeautifulSoup
def notify(title, text):
os.system("""
osascript -e 'display notification "{}" with title "{}"'
""".format(text, title))
url = "https://www.lenovo.com/us/en/p/laptops/legion-laptops/legion-slim-series-laptops/lenovo-legion-slim-7i-gen-8-(16-inch-intel)/len101g0028"
# url = "https://www.lenovo.com/us/en/p/laptops/legion-laptops/legion-slim-series-laptops/legion-slim-5i-gen-8-(16-inch-intel)/len101g0027?orgRef=https%253A%252F%252Fwww.google.com%252F"
coming_soon_text = "coming soon"
shop_text = "shop similar products"
# Make a GET request to the Lenovo website
agent = {"User-Agent":"Mozilla/5.0"}
response = requests.get(url, headers=agent)
# Parse the HTML code using BeautifulSoup
soup = BeautifulSoup(response.content, "html.parser")
# # Find the element containing the "coming soon" text
# element = soup.find("div", class_="coming-soon-wrapper")
# if element:
# # Check if the element's text contains the "coming soon" string
# if coming_soon_text in element.text.lower():
# sys.exit()
# element = soup.find("div", class_="shop-similar-wrapper")
# if element:
# if shop_text in element.text.lower():
# sys.exit()
# element = soup.find("div", class_="price_box")
# if element:
# notify("Laptop released!", 'The Legion Slim 7i Gen 8 (16-inch) is now available!')
elements = soup.find_all("button", class_="cta-button")
if elements:
for element in elements:
if "build your pc" in element.text.lower():
notify("Laptop customizable!", 'The Legion Slim 7i Gen 8 (16-inch) is now customizable!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment