Created
April 11, 2020 04:35
-
-
Save theriley106/c43fa29930a01a20d55dcbb3f39d7cdd to your computer and use it in GitHub Desktop.
Script to Check Amazon Delivery Slot Availability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bs4 | |
from selenium import webdriver | |
import sys | |
import time | |
import random | |
import os | |
def makeNoise(): | |
if os.name == 'nt': | |
import winsound | |
duration = 1000 | |
freq = 440 | |
winsound.Beep(freq, duration) | |
else: | |
os.system("say whole foods is ready") | |
def isSignedIn(html): | |
page = bs4.BeautifulSoup(html, 'lxml') | |
if 'Sign in' in page.select('#nav-link-accountList .nav-line-1')[0].getText(): | |
return False | |
return True | |
def getWFSlot(productUrl): | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_argument("user-data-dir=chromeData/") | |
driver = webdriver.Chrome("./chromedriver", chrome_options=chrome_options) | |
driver.get(productUrl) | |
html = driver.page_source | |
if isSignedIn(html) == False: | |
raw_input("Press enter when signed in") | |
driver.get(productUrl) | |
soup = bs4.BeautifulSoup(html) | |
time.sleep(60) | |
no_open_slots = True | |
while no_open_slots: | |
driver.get(productUrl) | |
print("refreshed") | |
html = driver.page_source | |
soup = bs4.BeautifulSoup(html) | |
time.sleep(9 + random.randint(0, 5)) | |
slot_pattern = 'Next available' | |
try: | |
next_slot_text = soup.find('h4', class_ ='ufss-slotgroup-heading-text a-text-normal').text | |
if slot_pattern in next_slot_text: | |
print('SLOTS OPEN!') | |
makeNoise() | |
no_open_slots = False | |
time.sleep(1400) | |
except AttributeError: | |
continue | |
try: | |
no_slot_pattern = 'No delivery windows available. New windows are released throughout the day.' | |
if no_slot_pattern == soup.find('h4', class_ ='a-alert-heading').text: | |
print("NO SLOTS!") | |
except AttributeError: | |
print('SLOTS OPEN!') | |
makeNoise() | |
no_open_slots = False | |
getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment