Python Inventory Search

I wrote a python script to query a website and check to see if an item is in stock. If it finds the product in question it will email me a report with a hyperlink so that I can click the link and place and order straight from my email. This script runs as a cron job (once every hour) and saves me the time of having to constantly check their website, wondering when they will get the next delivery.

It was a great exercise in using the BeautifulSoup4 python library as well as using selenium for the first time which was needed to flesh out the javascript that is creating the dynamic content.

from selenium import webdriver
from bs4 import BeautifulSoup as bs
from selenium.webdriver.firefox.options import Options
from selenium.common.exceptions import NoSuchElementException
import lxml
import smtplib
import time

options = Options()
options.headless = True

mylist = []
not_found = ''

driver = webdriver.Firefox(options=options)
driver.get("https://www.website.com)

# Try and fix the random timing errors --> better way is with selenium waitfor
time.sleep(5)

# Look for the state "no product in stock" --> "0 matches, that stinks"
try:
    not_found = driver.find_element_by_class_name("css-1ctldcn.ew1p50q2")
    not_found_html = not_found.get_attribute('innerHTML')

# handle the exception of product actually being found.
except NoSuchElementException as e:
    print (str(e))

# print "not found message" and exit program
if(not_found):
    print (not_found_html)
    driver.close()
    exit()

try: 

    # They have stock; now find how many products they have at runtime.
    products = driver.find_element_by_class_name("css-hecap1.ettsl931")
    total_products = products.get_attribute('innerHTML')

# handle the exception of product elements not being found and exit program
except NoSuchElementException as e:
    print (str(e))
    driver.close()
    exit()

# Find all of the Grid Elements, or all of the products available - all products use the same grid ID
element = driver.find_element_by_class_name("css-19ofktj.e29d1tf2")
html = element.get_attribute('innerHTML')
soup = bs(html, "lxml")

print (total_products)

for a in soup.find_all('a', href=True):
    mylist.append("Found the URL: https://www.website.com" + a['href'])

# Python 3 only
print (*mylist, sep="\n")

# See the whole tree with price and description for each item
# prettyHTML = soup.prettify()
# print (prettyHTML)

port = 587  
sender_email = "SENDER@gmail.com"
receiver_email = "RECEIVER@email.com"

message = """\
Subject: new products have arrived!

{}. """ .format(total_products) + str(mylist)

server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(sender_email, "SENDERPASSWORD")
server.sendmail(sender_email, receiver_email, message)
server.quit()

driver.close()
Posted in Python | Leave a comment

Free DNS subdomains

Free DNS subdomains via afraid.org is a great resource for lab and test machines.

They also have a free Dynamic DNS service which is a great way to keep tabs on your Home IP address in the event it should change. In the past I would use this to make sure I can VPN back to the house but now I have a OpenVPN server in a Data Center in Canada that I use.

Since I mentioned it, KimsUfi is a great resource for cheap servers. Pro Tip look for a “flash sale” to get a nice discount on your bill for as long as you continue rent the machine.

Posted in DNS, Networks | Leave a comment

DMVPN with BGP & OSPF

DMVPN with BGP and OSPF

Posted in bgp, dmvpn, Networks, ospf | Leave a comment

CCNP Enterprise – Valid Through 2023

Happy to say that I passed my CCNP re-certification after letting it expire in 2016. It felt good getting back in the lab and running through various routing and switching problems. I used EVE-NG to study with, it’s simply amazing software.

Posted in Uncategorized | Leave a comment

Site Reliability Engineering: How Google Runs Production Systems

If you support systems @ scale than you must read the Google SRE book!  Do yourself and your team a favor by making sure you don’t repeat the mistakes in this book! This should be required reading for all managers and front line engineers.

Posted in Books | Leave a comment

Delegated Credentials: Improving the security of TLS certificates

This is worthy of a share if you are interested in TLS. Facebook, Cloudflare, and Mozilla are working together with the ITEF to develop a new protocol for handling the private keys for SSL certs. Facebook Engineering gives a great overview in the article below.

https://engineering.fb.com/security/delegated-credentials/
Posted in Security | Leave a comment

Tutanota: Secure email, calendar and contact list

Today I upgraded my email provider to Tutanota. They provide encrypted email hosted on servers in Germany. In addition to the encrypted inbox you can easily send end to end encrypted emails with users of other services like Gmail. Fellow Tutanota users have their emails automatically encrypted end to end with no effort at all on their part as it’s built into the service by default.

I opted for the premium service and was able to set this up using my own domain name and was provided 5 email aliases. Price was very reasonable and it was a HUGE security improvement over the crappy email service my hosting provider was giving me. I highly encourage everyone to checkout this open source email service that focuses on privacy and security and ditch your Gmail account that scans your emails to deliver ads!

Posted in Security | Leave a comment

Site Back Online

Website is back online after a small hiatus. I’m pretty sure my old wordpress instance had been hacked so I nuked the entire site and left it dormant for awhile. Now I’m starting to rebuild it to highlight some of the things I’m interested in.

It’s a work in progress so bookmark the site and check back if you like, but it will probably be hacked again since my hosting provider sucks so bad at security. I’ll need to look into alternatives after reading an article about how easy it is to hack their console site 🙁

Posted in Uncategorized | Leave a comment