Skip to content

Instantly share code, notes, and snippets.

Created May 8, 2018 00:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ViennaMike/119c3f7430b4b440841e26b0b4271924 to your computer and use it in GitHub Desktop.
Checks nearest Virginia ABC stores for Buffalo Trace bourbon inventory, sends text message if any is in stock.
import logging
import datetime
import time
# from bs4 import BeautifulSoup
from selenium import webdriver
from import Client
accountSID='SID Here'
authToken = 'token here'
stores = {'219': 'Old Courthouse' , '231': 'Maple Ave.'}
# options = webdriver.ChromeOptions()
# options.add_argument('headless')
# driver = webdriver.Chrome('c:/program files (x86)/chromedriver.exe')
driver = webdriver.PhantomJS(executable_path="/var/task/phantomjs", service_log_path='/tmp/ghostdriver.log')
def myhandler(event, context):
results = ''
success = 0
for store in stores:
make_my_store = driver.find_element_by_id('make-this-my-store')
element = driver.find_element_by_css_selector('td[data-title="Inventory"]')
# page2Soup = BeautifulSoup(driver.page_source, 'lxml')
# element = page2Soup.find("td", {"data-title": "Inventory"})
inventory_value = element.text
if inventory_value <> '0': success = 1
results= results+stores[store] +' has '+inventory_value+ ' bottles of Buffalo Trace. '
# Send results if inventory not 0 at both stores
if success == 1:
results = 'Success! ' + results
twilioCli = Client(accountSID, authToken)
myTwilioNumber = 'myPhoneNumberHere'
destinationCellNumber = 'destinationCellNumberHere'
message = twilioCli.messages.create(body=results,from_=myTwilioNumber, to=destinationCellNumber)
except Exception as e:
logging.error(str(' Error at %s', 'division', exc_info=e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment