Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Last active January 14, 2023 23:29
Show Gist options
  • Save vadimkantorov/fa9a098be338105bc2a2084ad3fcb9ce to your computer and use it in GitHub Desktop.
Save vadimkantorov/fa9a098be338105bc2a2084ad3fcb9ce to your computer and use it in GitHub Desktop.
A Bash script to monitor "Echange d'un permis de conduire hors Union Européenne" rendez-vous availability at Prefecture de Paris
#! /bin/bash
#Usage:
# 1. Download the script to Home folder and open the Terminal
# 2. Put in your e-mail and SendGrid bearer token to get a notification of success
# 3. Open the Terminal and run the script: "$ bash ~/rdv_echange_permis_conduire_paris.sh"
# 4. Get your RDV! Right now the script will exit once it found a RDV available. It would dump the HTML of the page to "~/rdv_naturalisation_saint_denis.sh.html". Comment the line 38 to continue checking.
set -e
SENDGRID_BEARER_TOKEN='' # should start with "SG."
SENDGRID_EMAIL='' # put your e-mail here
TIMEOUT=30 # timeout between checks in seconds
URL='https://www.rdv-permisdeconduire-ppol.interieur.gouv.fr/eAppointment/dwr/call/plaincall/AjaxSelectionFormFeeder.getClosedDaysList.dwr'
URLCOOKIE='https://www.rdv-permisdeconduire-ppol.interieur.gouv.fr/eAppointment/appointment.do?preselectservice=PAR&sitekey=site2&userZip=75001'
NORDV='125'
ERROR='Throwable'
while true; do
OUTPUT=$(curl -sS $URL -H 'Content-Type: text/plain' -H "Cookie: $COOKIE" --data-binary $'callCount=1\npage=/eAppointment/element/jsp/appointment.jsp\nhttpSessionId=\nscriptSessionId=6D8501EBAC2D852925C5C905DE21B23A147\nc0-scriptName=AjaxSelectionFormFeeder\nc0-methodName=getClosedDaysList\nc0-id=0\nc0-param0=boolean:false\nc0-param1=string:site2\nc0-param2=string:760\nbatchId=1\n' -L --connect-timeout $TIMEOUT --max-time $TIMEOUT | tail -n 1 || echo "$ERROR")
if [[ "$OUTPUT" == *"$ERROR"* ]]; then
echo "$(date) Error: $OUTPUT"
echo "$(date) Need new cookie"
COOKIE="JSESSIONID=$(curl -sSi $URLCOOKIE --connect-timeout $TIMEOUT --max-time $TIMEOUT | grep Location: | sed 's/jsessionid=/\n/g' | tail -n 1)"
echo "$(date) Set cookie: $COOKIE"
elif [[ $(echo $OUTPUT | sed 's/"/\n/g' | wc -l) == *"$NODRV"* ]]; then
echo "$(date) No rendez-vous available. Next 62 days taken: $OUTPUT"
else
echo "$(date) YHOO! RDV ON INTERWEBZ. GET IT FOR THE DAY MISSING FROM THE LIST (YYYY-MM-DD): $OUTPUT"
echo "$OUTPUT" > "$0.html"
if [[ "$SENDGRID_BEARER_TOKEN" ]]; then
curl -sS -X POST https://api.sendgrid.com/api/mail.send.json -H "Authorization: Bearer $SENDGRID_BEARER_TOKEN" -d "to=$SENDGRID_EMAIL" -d "from=$SENDGRID_EMAIL" -d "subject=RDV available" -d"text=$URLCOOKIE"
fi
exit 0 # comment to continue even after an available RDV was found
fi
sleep $TIMEOUT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment