Skip to content

Instantly share code, notes, and snippets.

@ryanvillarreal
Created May 5, 2021 04:23
Show Gist options
  • Save ryanvillarreal/08f8a49d86e343bb0381ae3efc6aaed0 to your computer and use it in GitHub Desktop.
Save ryanvillarreal/08f8a49d86e343bb0381ae3efc6aaed0 to your computer and use it in GitHub Desktop.
Checking Sim-Lab inventory
#!/usr/bin/python3
from bs4 import BeautifulSoup
import requests,time
from pushover import init,Client
from datetime import datetime
api = "<INSERT PUSHOVER API KEY>"
user_key = "<INSERT PUSHOVER USER KEY>"
// mostly meant for simlab, would need to change the mechanics to check other sites.
base_url = "https://sim-lab.eu/shop/product/gt1-evo-direct-drive-mount-447?page=2#attr=400"
def sendToast(msg):
init(api)
Client(user_key).send_message(msg, title="Sim-Lab Check")
def checkSite(url):
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print ("Checking at %s" % dt_string)
r = requests.get(url)
print ("Status Code: " + str(r.status_code))
soup = BeautifulSoup(r.content, 'html.parser')
item = soup.find('div',id='product_details').h1.text
print (item)
mydivs = soup.find_all("div", {"class": "show_hide_stock_change"})
for div in mydivs:
tmp = div.get_text(" ",strip=True)
if "out of stock" in tmp:
print (item + " is Out of Stock!")
print ("checking again in 5 minutes.")
else:
msg = item + " is In Stock!"
sendToast(msg)
quit()
if __name__ == "__main__":
print("starting script...")
sendToast("Starting Script...")
while True:
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print ("Starting at: %s" % dt_string)
checkSite(base_url)
time.sleep(300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment