Skip to content

Instantly share code, notes, and snippets.

@jkctech
Last active October 17, 2021 21:08
Show Gist options
  • Save jkctech/eaccc8c063528633537e56e3b7b76eea to your computer and use it in GitHub Desktop.
Save jkctech/eaccc8c063528633537e56e3b7b76eea to your computer and use it in GitHub Desktop.
Small 15-minute-made bot to scrape a catalog on the website www.dacoproducts.com and check for availability for specific items. Intended to be connected to a pushnotification system as a standalone.
import requests
# ========== SETTINGS ==========
# Item codes you want to look for.
# (https://www.dacoproducts.com/K2Order.php)
# Selected on 'Stock N°' column but with all spaces stripped
# Example: "DCB003b + DVD PAL" => "DCB003b+DVDPAL"
items = ["DCB000", "DCB002"]
str_available = "AVAILABLE!!!"
str_unavailable = "unavailable"
# ========== /SETTINGS ==========
# Makes list into dictionary
available = {}
for item in items:
available[item] = False
# Scrape Daco catalog
raw = requests.get("https://www.dacoproducts.com/K2Order.php").text.lower()
# Split on HTML Table rows
blocks = raw.split("<tr>")
del blocks[0]
#Loop over table rows
for block in blocks:
# Split on HTML Table cols
fields = block.split("<td")
del fields[0]
# If no href, not an item
# If no "add to cart", item is not available
# if ("<a href=" not in fields[0]):
if ("<a href=" not in fields[0] or "add to cart" not in block):
continue
# Dirtiest pattern selector I have ever made
id = fields[0].split(".php\">")[1].split("<")[0].replace("&nbsp;", "").replace(" ", "").upper()
# If we are actually looking for this item, update it in the dict
if (id in items):
available[id] = True
# Print all items we looked for
for item in available.keys():
print("{}: {}".format(item, str_available if available[item] else str_unavailable))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment