Skip to content

Instantly share code, notes, and snippets.

@Bardyl
Created March 29, 2020 11:03
Show Gist options
  • Save Bardyl/58dbb510e6e0412ab23540be6f28484c to your computer and use it in GitHub Desktop.
Save Bardyl/58dbb510e6e0412ab23540be6f28484c to your computer and use it in GitHub Desktop.
Carrefour notification de créneau de livraison disponible
#!/usr/local/bin/python3
# For macOS only (replace notifier system to execute it on another system)
# Install terminal-notifier with gem install terminal-notifier
# Put this script into a cron job
from urllib.request import Request, urlopen
import json
import os
# Change variables here
postalCode = ""
lat = ""
lng = ""
eligibilityUrl = "https://www.carrefour.fr/api/eligibility?postalCode=" + postalCode + "&lat=" + lat + "&lng=" + lng
req = Request(eligibilityUrl)
req.add_header("x-requested-with", "XMLHttpRequest")
response = urlopen(req)
data = response.read()
values = json.loads(data)
if ("attributes" in values["data"] and "storeRef" in values["data"]["attributes"]):
storeRef = values["data"]["attributes"]["storeRef"]
slotsUrl = "https://www.carrefour.fr/api/firstslot?storeId=" + storeRef
req = Request(slotsUrl)
req.add_header("x-requested-with", "XMLHttpRequest")
response = urlopen(req)
data = response.read().decode("utf-8")
if (data != "[]"):
title = '-title {!r}'.format("Carrefour")
message = '-message {!r}'.format("Créneau de livraison disponible !")
os.system('/usr/local/bin/terminal-notifier {} -sound default'.format(" " . join([message, title])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment