Skip to content

Instantly share code, notes, and snippets.

@jacobsoo
Created April 18, 2020 06:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobsoo/7d40bee9933d42e025b0483a9df21d53 to your computer and use it in GitHub Desktop.
Save jacobsoo/7d40bee9933d42e025b0483a9df21d53 to your computer and use it in GitHub Desktop.
This is just a simple script for Covid-19 to check if there are any delivery timeslots based on your postal code.
import os, sys, re
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def _log(szString):
print(szString)
def main(PostalCode):
'''
Fairprice
HTTP GET - https://website-api.omni.fairprice.com.sg/api/slot-availability?address%5Baddress%5D=&address%5Blatitude%5D=1.39461688537769&address%5Blongitude%5D=103.745768782105&address%5Bpincode%5D=<Insert_Your_Postal_Code>&storeId=165
Giant
HTTP POST - https://giant.sg/checkout/cart/checkdelivery
Data to send is postal_code=<Insert_Your_Postal_Code>
Cold Storage
https://coldstorage.com.sg/checkout/cart/checkdelivery
Data to send is postal_code=<Insert_Your_Postal_Code>
Sheng Siong
HTTP POST - https://www.allforyou.sg/Common/pinCodeSearch
Data to send is code=<Insert_Your_Postal_Code>
You can try adding Redmart to the list
https://redmart-delivery-schedule.lazada.sg/schedule?hybrid=1
'''
FP_URL = "https://website-api.omni.fairprice.com.sg/api/slot-availability?address%5Baddress%5D=&address%5Blatitude%5D=1.39461688537769&address%5Blongitude%5D=103.745768782105&address%5Bpincode%5D=" + PostalCode + "&storeId=165"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36'
}
resp = requests.get(FP_URL, allow_redirects=True, verify=False, headers=headers)
szContents = resp.content.decode('utf-8')
matchObj = re.search(r'available\":(.*?)\}\}', szContents, re.DOTALL|re.UNICODE)
if matchObj:
if matchObj[1] == "false":
_log("[-] No delivery slots from Fairprice.com")
else:
_log("[+] Data from Fairprice.com : %s" % (matchObj[1]))
G_URL = "https://giant.sg/checkout/cart/checkdelivery"
data = {"postal_code": PostalCode}
resp = requests.post(G_URL, data=data, allow_redirects=True, verify=False, headers=headers)
szContents = resp.text
matchObj = re.search(r'earliest\"\:\[(.*?)\]\}', szContents, re.DOTALL|re.UNICODE)
if matchObj[1]=='':
_log("[-] No delivery slots from Giant.sg")
else:
_log("[+] Awesome, there are time slots : %s" % (matchObj[1]))
CS_URL = "https://coldstorage.com.sg/checkout/cart/checkdelivery"
data = {"postal_code": PostalCode}
resp = requests.post(CS_URL, data=data, allow_redirects=True, verify=False, headers=headers)
szContents = resp.text
matchObj = re.search(r'earliest\"\:\[(.*?)\]\}', szContents, re.DOTALL|re.UNICODE)
if matchObj[1]=='':
_log("[-] No delivery slots from Coldstorage.com.sg")
else:
_log("[+] Awesome, there are time slots : %s" % (matchObj[1]))
SS_URL = "https://www.allforyou.sg/Common/pinCodeSearch"
data = {"code": PostalCode, "pinStatus":1}
resp = requests.post(SS_URL, json=data, allow_redirects=True, verify=False, headers=headers)
szContents = resp.text
matchObj = re.search(r'response\"\:\"(.*?)"\}', szContents, re.DOTALL|re.UNICODE)
if matchObj[1]=='Failed':
_log("[-] No delivery slots from Sheng Siong (allforyou.sg)")
else:
_log("[+] Awesome, there are time slots : %s" % (matchObj[1]))
if __name__ == '__main__':
if (len(sys.argv) < 2):
_log("[+] Usage: %s [Postal_Code]" % sys.argv[0])
sys.exit(0)
else:
PostalCode = sys.argv[1]
_log("[+] Searching for timeslots for your postal code : %s" % (PostalCode))
main(PostalCode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment