Skip to content

Instantly share code, notes, and snippets.

@Apreche
Created May 17, 2021 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Apreche/02fd0f04fba17ca71243169345d60a0d to your computer and use it in GitHub Desktop.
Save Apreche/02fd0f04fba17ca71243169345d60a0d to your computer and use it in GitHub Desktop.
Dell monitor in stock checker
#!/usr/bin/env python3
import sys
import requests
import subprocess
from bs4 import BeautifulSoup
URL = "https://www.dell.com/en-us/shop/dell-ultrasharp-27-4k-usb-c-monitor-u2720q/apd/210-avjv/monitors-monitor-accessories"
CHECK = "Temporarily Out of Stock"
def email(message):
p = subprocess.Popen(
['msmtp', 'your@email.com'],
stdin=subprocess.PIPE
)
full_message = f"To: your@email.com\nFrom: your name <your@email.com>\nSubject: Dell Monitor\n\n{message}"
p.communicate(
bytes(full_message, 'utf-8')
)
response = requests.get(URL)
if response.status_code != 200:
email("Non-200 response on Monitor URL check")
sys.exit()
soup = BeautifulSoup(response.text, 'html.parser')
stock_level_wrappers = soup.find_all('div', class_="stock-level-wrapper")
stock_level_strings = []
for wrapper in stock_level_wrappers:
stock_level_strings.append(
wrapper.string.strip()
)
if CHECK not in stock_level_strings:
email("Monitor may be in stock")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment