With COVID19 and Coronavirus theres a huge surge in demand for Grocery Delivery Services such as AmazonFresh. In large cities like NYC, its nearly impossible to get a Delivery window. However, we can use a programming language called Python to help find them, and avoid having to stay in front of the PC for Hours refreshing the page in the hope that one will open up.



TLDR :

If your familiar with using Python the script is here – > (GitHub Link to Script)

Prerequisites :

First off you will need to install Python 3.4 which is what this was written for and a basic understanding of how it works. Use a code editor so you can test each chunk of code, I recommend PyCharm Community Edition.

Now, lets start coding!

First, You will need to import some Modules which are bits of software to give your script more functionality (lines 9-14). For example, using smtplib makes it possible to have the script generate and send an email.

You may not have some Modules of these installed, so you will need to install a utility called ‘pip‘ (see link on how to do this) and then navigate to where you’ve installed pip.exe , then run ‘pip.exe install <name of module>’

In PyCharm IDE you can also go to project interpreter settings and install modules there.



Next, Please also install a Web Driver, which is a special browser that can be controlled by software. In our case we will be browsing to AmazonFresh and performing a refresh. Take note of where the install is stored on your computer, we will need it later.

Now we start to code the main function. (refer to image below)

Line 16 names the Function and adds a URL as an Input.

Lines 17 and 18 include Headers which tell Amazon include your browser version.



Next on lines 20-25 , Webdriver makes a browser object from the Webdriver executable we just installed. We use ChromeDriver.



The rest of lines can be copied as-is. They define an html parser using the BeautifulSoup library which lets you read HTML of web-pages. Then time.sleep(60) waits 60 seconds for you to login and get to the delivery window page. Lastly, it sets a value to assume there’s no open slots.

Now we can make the main While loop. Lines 28-33 initiates a refresh action with the Webdriver.refresh() method , then reads the page and looks for the words “Next Available” which show up if a slot comes up.



If this phrase is found, it drops to line 37 and executes lines 38-46 which prints that message, then uses smtplib module to connect to your email provider, login, and send an email to you telling you Slots are now open! Quick run to the PC and checkout your cart and pay 🙂

PS – If you fill your credentials and host this script on Github, Dont commit/save them publicly.

After that while loop, it also has another section below that queries all of the current dates for the week, assuming no dates found on todays date. This completes the function and while loop.

Lastly, please make sure to include line 71, this actually initiates the code we just wrote above.

Good Luck! Please share if you used this to find a Slot!

If you found this useful and are interested in more Python, here is another quick Log Analysis script which can read text files and search for lines in them :

https://www.roamingviews.com/tech/quick-and-dirty-python-log-analysis/