Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyttsx3 text-to-speech module instead of os.system('say "..."') for cross-platform compatibility #32

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
chromedriver*
geckodriver*
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

# 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:
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```.
Expand Down Expand Up @@ -70,19 +68,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.
Meanwhile, if you'd not like to edit, there is a PR: https://github.com/pcomputo/Whole-Foods-Delivery-Slot/pull/32, you can try to switch to that branch to get audible notifications. I'm in the testing phasing of this PR.


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).
15 changes: 11 additions & 4 deletions amazon_fresh_delivery_slot_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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 = {
Expand Down Expand Up @@ -34,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)

Expand All @@ -48,7 +54,7 @@ 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:
Expand All @@ -59,6 +65,7 @@ def getWFSlot(productUrl):



sayIt("Starting")
getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1')


engine.stop()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 13 additions & 7 deletions whole_foods_delivery_autobuy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,11 +68,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):
Expand Down Expand Up @@ -108,7 +112,7 @@ def getWFSlot(productUrl):
for each_date in all_dates:
if slot_opened_text not in each_date.text:
print('SLOTS OPEN! 2')
os.system('say "Slots for delivery opened!"')
sayIt("Slots for delivery opened!")
no_open_slots = False
autoCheckout(driver)

Expand All @@ -121,12 +125,14 @@ 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)


getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1')
sayIt("Starting")

getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1')

engine.stop()
130 changes: 0 additions & 130 deletions whole_foods_delivery_autobuy_windows.py

This file was deleted.

13 changes: 10 additions & 3 deletions whole_foods_delivery_slot_REDUNDANT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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:
Expand All @@ -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()
16 changes: 12 additions & 4 deletions whole_foods_delivery_slot_chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
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 = {
'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, "html.parser")
Expand All @@ -32,7 +39,7 @@ def getWFSlot(productUrl):
for each_date in all_dates:
if slot_opened_text not in each_date.text:
print('SLOTS OPEN 2!')
os.system('say "Slots for delivery opened!"')
sayIt("Slots for delivery opened!")
no_open_slots = False
time.sleep(1400)
except AttributeError:
Expand All @@ -44,7 +51,7 @@ def getWFSlot(productUrl):
print("NO SLOTS!")
except AttributeError:
print('SLOTS OPEN 3!')
os.system('say "Slots for delivery opened!"')
sayIt("Slots for delivery opened!")
no_open_slots = False


Expand All @@ -53,7 +60,7 @@ def getWFSlot(productUrl):
next_slot_text = str([x.text for x in soup.findAll('h4', class_ ='ufss-slotgroup-heading-text a-text-normal')])
if any(next_slot_text in slot_pattern for slot_pattern in slot_patterns):
print('SLOTS OPEN!')
winsound.Beep(freq, duration)
sayIt("Slots for delivery opened!")
no_open_slots = False

autoCheckout(driver)
Expand All @@ -62,6 +69,7 @@ def getWFSlot(productUrl):
pass


sayIt("Starting")
getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1')


engine.stop()