From 01ed8002ff95a97198c51cbf6443b68c0a1b663c Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Sat, 4 Apr 2020 14:18:32 -0500 Subject: [PATCH 01/12] Basic Windows support --- .gitignore | 1 + whole_foods_delivery_slot_chrome.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2a78fc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +chromedriver.exe diff --git a/whole_foods_delivery_slot_chrome.py b/whole_foods_delivery_slot_chrome.py index 580a43f..41bfafd 100644 --- a/whole_foods_delivery_slot_chrome.py +++ b/whole_foods_delivery_slot_chrome.py @@ -6,6 +6,12 @@ import time import os +def sayIt(textToSay): + # mac command + # os.system('say "Slots for delivery opened!"') + # windows say command + command = 'PowerShell -Command "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\'{}\');"'.format(textToSay) + os.system(command) def getWFSlot(productUrl): headers = { @@ -31,7 +37,7 @@ def getWFSlot(productUrl): 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!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) except AttributeError: @@ -43,7 +49,7 @@ def getWFSlot(productUrl): for each_date in all_dates: if slot_opened_text not in each_date.text: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) except AttributeError: @@ -55,10 +61,11 @@ def getWFSlot(productUrl): print("NO SLOTS!") except AttributeError: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False +sayIt("Starting") getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') From c79d70a71800cd5c6916ed5d40c4a57e501caa28 Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Sat, 4 Apr 2020 14:24:31 -0500 Subject: [PATCH 02/12] Switched whole_foods_delivery_slot_chrome.py to use cross-platform TTS pyttsx3 --- requirements.txt | 1 + whole_foods_delivery_slot_chrome.py | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index e61fa79..24813be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ chromedriver-binary==81.0.4044.69.0 selenium==3.141.0 urllib3==1.25.8 webdriver-manager==2.3.0 +pyttsx3==2.7 diff --git a/whole_foods_delivery_slot_chrome.py b/whole_foods_delivery_slot_chrome.py index 41bfafd..029e39b 100644 --- a/whole_foods_delivery_slot_chrome.py +++ b/whole_foods_delivery_slot_chrome.py @@ -5,13 +5,13 @@ import sys import time import os +import pyttsx3 + +engine = pyttsx3.init() # object creation def sayIt(textToSay): - # mac command - # os.system('say "Slots for delivery opened!"') - # windows say command - command = 'PowerShell -Command "Add-Type -AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\'{}\');"'.format(textToSay) - os.system(command) + engine.say(textToSay) + engine.runAndWait() def getWFSlot(productUrl): headers = { @@ -68,4 +68,4 @@ def getWFSlot(productUrl): sayIt("Starting") getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') - +engine.stop() From e33d7e6f395c98815874276f1c89a427a2d2c3a8 Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Mon, 6 Apr 2020 15:50:59 -0500 Subject: [PATCH 03/12] Use pyttsx3 TTS library for rest of scripts instead of command-line say which only works with Macs --- .gitignore | 3 ++- amazon_fresh_delivery_slot_chrome.py | 11 +++++++++-- whole_foods_delivery_slot.py | 13 ++++++++++--- whole_foods_delivery_slot_firefox.py | 13 ++++++++++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f2a78fc..df99a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -chromedriver.exe +chromedriver* +geckodriver* diff --git a/amazon_fresh_delivery_slot_chrome.py b/amazon_fresh_delivery_slot_chrome.py index be08dd9..6f00d93 100644 --- a/amazon_fresh_delivery_slot_chrome.py +++ b/amazon_fresh_delivery_slot_chrome.py @@ -5,7 +5,13 @@ import sys import time import os +import pyttsx3 +engine = pyttsx3.init() # object creation + +def sayIt(textToSay): + engine.say(textToSay) + engine.runAndWait() def getWFSlot(productUrl): headers = { @@ -30,13 +36,14 @@ def getWFSlot(productUrl): open_slots = soup.find('div', class_ ='orderSlotExists').text() if open_slots != "false": print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!" no_open_slots = False time.sleep(1400) except AttributeError: continue +sayIt("Starting") getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') - +engine.stop() diff --git a/whole_foods_delivery_slot.py b/whole_foods_delivery_slot.py index ee2fc15..139269c 100644 --- a/whole_foods_delivery_slot.py +++ b/whole_foods_delivery_slot.py @@ -5,7 +5,13 @@ import sys import time import os +import pyttsx3 +engine = pyttsx3.init() # object creation + +def sayIt(textToSay): + engine.say(textToSay) + engine.runAndWait() def getWFSlot(productUrl): headers = { @@ -31,7 +37,7 @@ def getWFSlot(productUrl): 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!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) except AttributeError: @@ -43,10 +49,11 @@ def getWFSlot(productUrl): print("NO SLOTS!") except AttributeError: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False +sayIt("Starting") getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') - +engine.stop() diff --git a/whole_foods_delivery_slot_firefox.py b/whole_foods_delivery_slot_firefox.py index 7d2cf05..22261c6 100644 --- a/whole_foods_delivery_slot_firefox.py +++ b/whole_foods_delivery_slot_firefox.py @@ -5,7 +5,13 @@ import sys import time import os +import pyttsx3 +engine = pyttsx3.init() # object creation + +def sayIt(textToSay): + engine.say(textToSay) + engine.runAndWait() def getWFSlot(productUrl): driver = webdriver.Firefox() @@ -27,7 +33,7 @@ def getWFSlot(productUrl): 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!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) except AttributeError: @@ -39,10 +45,11 @@ def getWFSlot(productUrl): print("NO SLOTS!") except AttributeError: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False +sayIt("Starting") getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') - +engine.stop() From acaa4e22457be2ea91564e3ffbe42e35da93a25c Mon Sep 17 00:00:00 2001 From: jason123santa <51246585+jason123santa@users.noreply.github.com> Date: Thu, 9 Apr 2020 15:38:47 -0400 Subject: [PATCH 04/12] Update whole_foods_delivery_slot_firefox.py --- whole_foods_delivery_slot_firefox.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/whole_foods_delivery_slot_firefox.py b/whole_foods_delivery_slot_firefox.py index 22261c6..826d20b 100644 --- a/whole_foods_delivery_slot_firefox.py +++ b/whole_foods_delivery_slot_firefox.py @@ -5,6 +5,7 @@ import sys import time import os +import winsound import pyttsx3 engine = pyttsx3.init() # object creation @@ -14,7 +15,7 @@ def sayIt(textToSay): engine.runAndWait() def getWFSlot(productUrl): - driver = webdriver.Firefox() + driver = webdriver.Firefox(executable_path=r"C:\Users\jason\Downloads\geckodriver-v0.26.0-win64\geckodriver.exe") driver.get(productUrl) html = driver.page_source soup = bs4.BeautifulSoup(html) @@ -28,16 +29,28 @@ def getWFSlot(productUrl): soup = bs4.BeautifulSoup(html) time.sleep(4) - slot_pattern = 'Next available' + slot_patterns = ['Next available', '1-hour delivery windows', '2-hour delivery windows'] try: next_slot_text = soup.find('h4', class_ ='ufss-slotgroup-heading-text a-text-normal').text - if slot_pattern in next_slot_text: + if any(next_slot_text in slot_pattern for slot_pattern in slot_patterns): print('SLOTS OPEN!') sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) except AttributeError: - continue + pass + + try: + slot_opened_text = "Not available" + all_dates = soup.findAll("div", {"class": "ufss-date-select-toggle-text-availability"}) + for each_date in all_dates: + if slot_opened_text not in each_date.text: + print('SLOTS OPEN!') + sayIt("Slots for delivery opened!") + no_open_slots = False + time.sleep(1400) + except AttributeError: + pass try: no_slot_pattern = 'No delivery windows available. New windows are released throughout the day.' @@ -48,7 +61,6 @@ def getWFSlot(productUrl): sayIt("Slots for delivery opened!") no_open_slots = False - sayIt("Starting") getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') From d978f843cfc76909aa6b3d55dcd96f7c0240362d Mon Sep 17 00:00:00 2001 From: jason123santa <51246585+jason123santa@users.noreply.github.com> Date: Thu, 9 Apr 2020 16:27:07 -0400 Subject: [PATCH 05/12] Update whole_foods_delivery_slot_chrome.py --- whole_foods_delivery_slot_chrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whole_foods_delivery_slot_chrome.py b/whole_foods_delivery_slot_chrome.py index 029e39b..a004f93 100644 --- a/whole_foods_delivery_slot_chrome.py +++ b/whole_foods_delivery_slot_chrome.py @@ -32,7 +32,7 @@ def getWFSlot(productUrl): soup = bs4.BeautifulSoup(html) time.sleep(4) - slot_pattern = 'Next available' + slot_patterns = ['Next available', '1-hour delivery windows', '2-hour delivery windows'] try: next_slot_text = soup.find('h4', class_ ='ufss-slotgroup-heading-text a-text-normal').text if slot_pattern in next_slot_text: From e7db50eba794c1627ad86cb04d9c6ab4914f555f Mon Sep 17 00:00:00 2001 From: jason123santa <51246585+jason123santa@users.noreply.github.com> Date: Thu, 9 Apr 2020 16:35:34 -0400 Subject: [PATCH 06/12] Update whole_foods_delivery_slot_chrome.py Added 1-hour delivery windows and 2-hour delivery windows --- whole_foods_delivery_slot_chrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whole_foods_delivery_slot_chrome.py b/whole_foods_delivery_slot_chrome.py index a004f93..6b09c5e 100644 --- a/whole_foods_delivery_slot_chrome.py +++ b/whole_foods_delivery_slot_chrome.py @@ -18,7 +18,7 @@ def getWFSlot(productUrl): 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', } - driver = webdriver.Chrome() + driver = webdriver.Chrome(executable_path=r"C:\Users\jason\Downloads\chromedriver_win32\chromedriver.exe") driver.get(productUrl) html = driver.page_source soup = bs4.BeautifulSoup(html) From 1df0273a3f18fb9df5643b386f7eda7ce1e076ce Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Fri, 10 Apr 2020 11:03:32 -0500 Subject: [PATCH 07/12] Removed browser driver executable path --- whole_foods_delivery_slot_chrome.py | 3 ++- whole_foods_delivery_slot_firefox.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/whole_foods_delivery_slot_chrome.py b/whole_foods_delivery_slot_chrome.py index 6b09c5e..3cb9922 100644 --- a/whole_foods_delivery_slot_chrome.py +++ b/whole_foods_delivery_slot_chrome.py @@ -18,7 +18,8 @@ def getWFSlot(productUrl): 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', } - driver = webdriver.Chrome(executable_path=r"C:\Users\jason\Downloads\chromedriver_win32\chromedriver.exe") + driver = webdriver.Chrome() +# driver = webdriver.Chrome(executable_path=r"C:\Users\jason\Downloads\chromedriver_win32\chromedriver.exe") driver.get(productUrl) html = driver.page_source soup = bs4.BeautifulSoup(html) diff --git a/whole_foods_delivery_slot_firefox.py b/whole_foods_delivery_slot_firefox.py index 826d20b..eaddbc8 100644 --- a/whole_foods_delivery_slot_firefox.py +++ b/whole_foods_delivery_slot_firefox.py @@ -15,7 +15,8 @@ def sayIt(textToSay): engine.runAndWait() def getWFSlot(productUrl): - driver = webdriver.Firefox(executable_path=r"C:\Users\jason\Downloads\geckodriver-v0.26.0-win64\geckodriver.exe") + driver = webdriver.Firefox() +# driver = webdriver.Firefox(executable_path=r"C:\Users\jason\Downloads\geckodriver-v0.26.0-win64\geckodriver.exe") driver.get(productUrl) html = driver.page_source soup = bs4.BeautifulSoup(html) From fdeb41474cf261ea80d118227f90aa6f6ee10df9 Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Fri, 10 Apr 2020 11:19:38 -0500 Subject: [PATCH 08/12] Switched newer scripts/changes over to pyttsx3 TTS module --- amazon_fresh_delivery_slot_chrome.py | 4 ++-- whole_foods_delivery_autobuy.py | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/amazon_fresh_delivery_slot_chrome.py b/amazon_fresh_delivery_slot_chrome.py index 3cf6cf2..e44f457 100644 --- a/amazon_fresh_delivery_slot_chrome.py +++ b/amazon_fresh_delivery_slot_chrome.py @@ -40,12 +40,12 @@ def getWFSlot(productUrl): pass else: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) except NoSuchElementException: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) diff --git a/whole_foods_delivery_autobuy.py b/whole_foods_delivery_autobuy.py index e83d380..e4a5e4e 100644 --- a/whole_foods_delivery_autobuy.py +++ b/whole_foods_delivery_autobuy.py @@ -9,7 +9,13 @@ import sys import time import os +import pyttsx3 +engine = pyttsx3.init() # object creation + +def sayIt(textToSay): + engine.say(textToSay) + engine.runAndWait() def autoCheckout(driver): driver = driver @@ -52,11 +58,9 @@ def autoCheckout(driver): review_select_continue.click() print("Order reviewed") - print("Order Placed!") - os.system('say "Order Placed!"') + sayIt("Order Placed!") except NoSuchElementException: - print("Found a slot but it got taken, run script again.") - os.system('say "Found a slot but it got taken, run script again."') + sayIt("Found a slot but it got taken, run script again.") time.sleep(1400) def getWFSlot(productUrl): @@ -84,7 +88,7 @@ def getWFSlot(productUrl): next_slot_text = soup.find('h4', class_ ='ufss-slotgroup-heading-text a-text-normal').text if any(next_slot_text in slot_pattern for slot_pattern in slot_patterns): print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False autoCheckout(driver) @@ -98,7 +102,7 @@ def getWFSlot(productUrl): for each_date in all_dates: if slot_opened_text not in each_date.text: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False autoCheckout(driver) @@ -111,12 +115,13 @@ def getWFSlot(productUrl): print("NO SLOTS!") except AttributeError: print('SLOTS OPEN!') - os.system('say "Slots for delivery opened!"') + sayIt("Slots for delivery opened!") no_open_slots = False autoCheckout(driver) +sayIt("Starting") getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') - +engine.stop() From b2218cc51834f2154842f04a768ab8c3ac098ee2 Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Fri, 10 Apr 2020 11:30:39 -0500 Subject: [PATCH 09/12] Updated README for pyttsx3 --- README.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/README.md b/README.md index 8b155a3..6e291b2 100644 --- a/README.md +++ b/README.md @@ -70,19 +70,5 @@ _Note, I haven't written this blog, but I'd like to thank the person (don't who # FAQ ## say is not a recognized command -If say is not native to your OS. Please try using winsound. Comment/delete the code in the script that has `os.system('say...')` and incorporate the following snippet: - -`import winsound` - -`duration = 1000` - -`freq = 440` - -~~os.system('say ...')~~ - -`winsound.Beep(freq, duration)` - -As an example, you can look at any of the Windows scripts. Also, there are certain issues in this repository revolving around this issue that have been solved. Please feel to check them out too. - - +This fork uses the [pyttsx3](https://pypi.org/project/pyttsx3/) module, so you shouldn't get a "say is not a recognized command" error as long as [pyttsx3 supports your platform and installed TTS libraries](https://pyttsx3.readthedocs.io/en/latest/support.html). From 53037f9db8ffbea749642e2560a785bb6b5e896b Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Fri, 10 Apr 2020 11:41:15 -0500 Subject: [PATCH 10/12] Removed redundant windows scripts since main scripts now use cross-platform pyttsx3 TTS module --- README.md | 2 - whole_foods_delivery_autobuy_windows.py | 126 ------------------------ whole_foods_delivery_windows.py | 52 ---------- 3 files changed, 180 deletions(-) delete mode 100644 whole_foods_delivery_autobuy_windows.py delete mode 100644 whole_foods_delivery_windows.py diff --git a/README.md b/README.md index 6e291b2..21d3435 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,6 @@ Supports **MacOS, Linux, and Windows**. The script works on **Chrome** (```whole_foods_delivery_slot_chrome.py``` for Whole Foods) (```amazon_fresh_delivery_slot_chrome.py``` for Amazon Fresh) and **FireFox** (```whole_foods_delivery_slot_firefox.py```) for now. This does not support "Autobuy feature". -Note, use the ```whole_foods_delivery_windows.py``` for Windows. Also, only for this OS, you'll have to install an additional package ```winsound``` - ### Autobuy feature: If you'd like the script to select the first available time, and proceed all the way through checkout, please use the ```whole_foods_delivery_autobuy.py```. diff --git a/whole_foods_delivery_autobuy_windows.py b/whole_foods_delivery_autobuy_windows.py deleted file mode 100644 index e30cc7c..0000000 --- a/whole_foods_delivery_autobuy_windows.py +++ /dev/null @@ -1,126 +0,0 @@ -import bs4 - -from selenium import webdriver -from selenium.common.exceptions import NoSuchElementException -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver.common.by import By - -import sys -import time -import os - -import winsound - - -def autoCheckout(driver): - driver = driver - - time.sleep(1) - try: - slot_select_button = driver.find_element_by_xpath('/html/body/div[5]/div[1]/div/div[2]/div/div/div/div/div[1]/div[4]/div[2]/div/div[3]/div/div/ul/li/span/span/div/div[2]/span/span/button') - slot_select_button.click() - print("Clicked open slot") - except NoSuchElementException: - slot_select_button = driver.find_element_by_xpath('/html/body/div[5]/div[1]/div/div[2]/div/div/div/div/div[1]/div[4]/div[2]/div/div[4]/div/div/ul/li/span/span/div/div[2]/span/span/button') - slot_select_button.click() - - slot_continue_button = driver.find_element_by_xpath('/html/body/div[5]/div[1]/div/div[2]/div/div/div/div/div[2]/div[3]/div/span/span/span/input') - slot_continue_button.click() - print("Selected slot and continued to next page") - - try: - time.sleep(6) - outofstock_select_continue = driver.find_element_by_xpath('/html/body/div[5]/div/form/div[25]/div/div/span/span/input') - outofstock_select_continue.click() - print("Passed out of stock") - except NoSuchElementException: - pass - - try: - time.sleep(6) - payment_select_continue = driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[2]/div[2]/div[4]/div/form/div[3]/div[1]/div[2]/div/div/div/div[1]/span/span/input') - payment_select_continue.click() - print("Payment method selected") - - - time.sleep(6) - try: - review_select_continue = driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[2]/form/div/div/div/div[2]/div/div[1]/div/div[1]/div/span/span/input') - review_select_continue.click() - print("Order reviewed") - except NoSuchElementException: - review_select_continue = driver.find_element_by_xpath('/html/body/div[5]/div[1]/div[2]/form/div/div/div/div[2]/div[2]/div/div[1]/span/span/input') - review_select_continue.click() - print("Order reviewed") - - print("Order Placed!") - winsound.Beep(freq, duration) - except NoSuchElementException: - print("Found a slot but it got taken, run script again.") - winsound.Beep(freq, duration) - time.sleep(1400) - -def getWFSlot(productUrl): - headers = { - 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', - } - duration = 1000 - freq = 440 - - driver = webdriver.Chrome() - driver.get(productUrl) - driver.maximize_window() - html = driver.page_source - soup = bs4.BeautifulSoup(html, "html.parser") - time.sleep(60) - no_open_slots = True - - while no_open_slots: - driver.refresh() - print("refreshed") - html = driver.page_source - soup = bs4.BeautifulSoup(html) - time.sleep(4) - - slot_patterns = ['Next available', '1-hour delivery windows', '2-hour delivery windows'] - try: - next_slot_text = soup.find('h4', class_ ='ufss-slotgroup-heading-text a-text-normal').text - if any(next_slot_text in slot_pattern for slot_pattern in slot_patterns): - print('SLOTS OPEN!') - winsound.Beep(freq, duration) - no_open_slots = False - - autoCheckout(driver) - - except AttributeError: - pass - - try: - slot_opened_text = "Not available" - all_dates = soup.findAll("div", {"class": "ufss-date-select-toggle-text-availability"}) - for each_date in all_dates: - if slot_opened_text not in each_date.text: - print('SLOTS OPEN!') - winsound.Beep(freq, duration) - no_open_slots = False - autoCheckout(driver) - - except AttributeError: - pass - - 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!') - winsound.Beep(freq, duration) - no_open_slots = False - - autoCheckout(driver) - - -getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') - - diff --git a/whole_foods_delivery_windows.py b/whole_foods_delivery_windows.py deleted file mode 100644 index e028e21..0000000 --- a/whole_foods_delivery_windows.py +++ /dev/null @@ -1,52 +0,0 @@ -import bs4 - -from selenium import webdriver - -import sys -import time - -import winsound - - -def getWFSlot(productUrl): - driver = webdriver.Chrome() - driver.get(productUrl) - html = driver.page_source - soup = bs4.BeautifulSoup(html) - time.sleep(60) - no_open_slots = True - - duration = 1000 - freq = 440 - - while no_open_slots: - driver.refresh() - print("refreshed") - html = driver.page_source - soup = bs4.BeautifulSoup(html) - time.sleep(4) - - 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!') - winsound.Beep(freq, duration) - 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!') - winsound.Beep(freq, duration) - no_open_slots = False - - -getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1') - - From 935391231ab2a0e2b170d812eea12fad7aa3e4f1 Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Fri, 10 Apr 2020 11:42:29 -0500 Subject: [PATCH 11/12] Fix readme typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 21d3435..f6ff1f4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ # Whole Foods and Amazon Fresh Delivery Slot Automated Script -Yes, amid COVID-19 trying to get Whole Foods and Amazon Fresh delivery slots can get cumbersome. To free you off the constant hassle of checking for slots (and almost never finding one), this automated script can notify you (yes notifies you verbally, so you can go about your tasks) of when new delivery slots open. +Yes, amid COVID-19 trying to get Whole Foods and Amazon Fresh delivery slots can get cumbersome. To free you of the constant hassle of checking for slots (and almost never finding one), this automated script can notify you (yes notifies you verbally, so you can go about your tasks) of when new delivery slots open. ## Usage: From 57b8f6a62ed0188be3eb07a9e0cab2705cd93689 Mon Sep 17 00:00:00 2001 From: Jason Spangler Date: Sun, 19 Apr 2020 16:19:17 -0500 Subject: [PATCH 12/12] Added missing paren --- amazon_fresh_delivery_slot_chrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amazon_fresh_delivery_slot_chrome.py b/amazon_fresh_delivery_slot_chrome.py index e44f457..e03bd4a 100644 --- a/amazon_fresh_delivery_slot_chrome.py +++ b/amazon_fresh_delivery_slot_chrome.py @@ -54,7 +54,7 @@ def getWFSlot(productUrl): open_slots = soup.find('div', class_ ='orderSlotExists').text() if open_slots != "false": print('SLOTS OPEN!') - sayIt("Slots for delivery opened!" + sayIt("Slots for delivery opened!") no_open_slots = False time.sleep(1400) except AttributeError: