Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 twilio.rest 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):
try:
results = ''
success = 0
for store in stores:
driver.get('https://www.abc.virginia.gov/stores/'+store)
make_my_store = driver.find_element_by_id('make-this-my-store')
make_my_store.click()
time.sleep(5)
driver.get('https://www.abc.virginia.gov/products/bourbon/buffalo-trace-bourbon#/product?productSize=0')
time.sleep(5)
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. '
driver.close()
driver.quit()
# 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(datetime.datetime.now())+' 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
You can’t perform that action at this time.