Skip to content

Instantly share code, notes, and snippets.

@TaLinh
Forked from vadimkantorov/rdv_naturalisation.sh
Created January 16, 2024 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TaLinh/41f1c0590fef89f5d6d4a666a27da926 to your computer and use it in GitHub Desktop.
Save TaLinh/41f1c0590fef89f5d6d4a666a27da926 to your computer and use it in GitHub Desktop.
A Bash script to monitor naturalisation rendez-vous availability at Prefectures Bobigny, Nanterre. Consider renting one or several EC2 micro instances at Paris AWS data center to avoid bans.
# Usage:
# 1. Put in your email/SendGrid credentials or phone/Twilio credentials
# 2. Run as: "bash rdv_naturalisation.sh nanterre" or "bash rdv_naturalisation.sh bobigny" or "bash rdv_naturalisation.sh cre"
# 3. Get your RDV! The script will dump the HTML of the page and will continue execution even after the first RDV is found.
SENDGRID_BEARER_TOKEN='' # should start with "SG."
SENDGRID_EMAIL='' # put your e-mail here
TWILIO_SID='' # should start with "AC"
TWILIO_AUTH_TOKEN=''
TWILIO_FROM_NUMBER='' # put your Twilio Trial Phone Number here, should start with +
TWILIO_TO_NUMBER='' # put your cell phone number here, should start with +
TIMEOUT=300 # timeout between checks in seconds
set -e
#URL='http://www.val-de-marne.gouv.fr/booking/create/4963/0' # DOES NOT WORK, NEEDS SOME FIXES
if [[ $1 == bobigny ]]; then
URL='http://www.seine-saint-denis.gouv.fr/booking/create/1194/0'
elif [[ $1 == nanterre ]]; then
URL='http://www.hauts-de-seine.gouv.fr/booking/create/13525/0'
elif [[ $1 == cre ]]; then
URL='http://pprdv.interieur.gouv.fr/booking/create/953/0'
else
echo "Exiting. Not supported [$1]"
exit 1
fi
NORDV='existe plus de plage horaire libre pour votre demande'
MAYBERDV='Description de la nature du rendez-vous'
GETCOOKIE='Effectuer une demande de rendez-vous'
ERROR1='Guru Meditation'
ERROR2='Bad Gateway'
ERROR3='Bad request'
ERROR4='Forbidden'
ERROR5='Service Unavailable'
ERROR6='Gateway Time-out'
while true; do
OUTPUT=$(curl -sS $URL -H 'Content-Type: application/x-www-form-urlencoded' -H "Cookie: $COOKIE" --data 'condition=on&nextButton=Effectuer+une+demande+de+rendez-vous' -L --connect-timeout $TIMEOUT --max-time $TIMEOUT || echo "$ERROR1")
if [[ "$OUTPUT" == *"$GETCOOKIE"* ]]; then
echo "$(date) Need new cookie"
COOKIE=$(curl -sS --head $URL --connect-timeout $TIMEOUT --max-time $TIMEOUT | grep -i Set-Cookie | cut -d':' -f2 | cut -d';' -f1 | sed 's/[[:space:]]*$//g' | sed 's/^[[:space:]]*//')
echo "$(date) Set cookie: $COOKIE"
elif [[ "$OUTPUT" == *"$NORDV"* ]]; then
echo "$(date) No rendez-vous available"
elif [[ "$OUTPUT" == *"$ERROR1"* ]] || [[ "$OUTPUT" == *"$ERROR2"* ]] || [[ "$OUTPUT" == *"$ERROR3"* ]] || [[ "$OUTPUT" == *"$ERROR4"* ]] || [[ "$OUTPUT" == *"$ERROR5"* ]] || [[ "$OUTPUT" == *"$ERROR6"* ]]; then
echo "$(date) Error"
echo "$OUTPUT" > "$0.error.html"
COOKIE=
sleep $(($TIMEOUT * 2))
else
echo "$(date) YHOO! RDV ON INTERWEBZ"
echo "$OUTPUT" > "$0.$(date +%s%N).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=$URL"
fi
if [[ "$TWILIO_SID" ]]; then
curl -sS -X POST https://api.twilio.com/2010-04-01/Accounts/${TWILIO_SID}/Messages.json -u "${TWILIO_SID}:${TWILIO_AUTH_TOKEN}" --data-urlencode "To=${TWILIO_TO_NUMBER}" --data-urlencode "From=${TWILIO_FROM_NUMBER}" --data-urlencode "Body=$URL"
fi
# exit 0 # uncommment to exit after the first RDV is found
fi
sleep $TIMEOUT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment