Last active
November 7, 2020 12:02
-
-
Save pauladams8/70d2b0938da6447ef6f0d31a4bc5ed14 to your computer and use it in GitHub Desktop.
Automatically retrieves available delivery slots from Ocado.com
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
### COPYRIGHT PAUL ADAMS 2020. ALL RIGHTS RESERVED. ### | |
import os | |
import time | |
import requests | |
import datetime | |
W3_SESSION_ID = "" # replace with your W3SESSIONID cookie | |
OCADO_SESSION_ID = "" # replace with your OCADOSESSIONID cookie | |
def notify(title, subtitle, message, notifySound): | |
t = '-title {!r}'.format(title) | |
s = '-subtitle {!r}'.format(subtitle) | |
m = '-message {!r}'.format(message) | |
n = '-sound {!r}'.format(notifySound) | |
os.system('terminal-notifier {}'.format(' '.join([m, t, s, n]))) | |
tomorrow = datetime.date.today() + datetime.timedelta(days=1) | |
try: | |
while True: | |
print("Searching for slots...") | |
res = requests.get('https://www.ocado.com/webshop/getUpdatedSlotBooking.do', params={ | |
'ajax': True, | |
'date': tomorrow.strftime('%Y-%m-%d') | |
}, headers={ | |
'X-Requested-With': 'XMLHttpRequest', # pretend we're making an ajax request | |
# pretend we're using Google Chrome | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36' | |
}, cookies={ | |
'W3SESSIONID': W3_SESSION_ID, | |
'OCADOSESSIONID': OCADO_SESSION_ID | |
}).json() | |
slots = [] | |
for day in res['days']: | |
for slotsByTime in day['slots'].values(): | |
slots += slotsByTime | |
if len(slots) < 1: | |
print("No slots found") | |
else: | |
notify("Slots found!", "Ocado.com", | |
"Delivery slots were found on Ocado.com", "blow") | |
time.sleep(5) | |
except KeyboardInterrupt: | |
print("Goodbye") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Paul, given Ocado’s recent changes to their website and slot availability, are you able to get this code to still run successfully?