-
-
Save vadimkantorov/c6942cc702cceec7ffb30a990c72df5e to your computer and use it in GitHub Desktop.
# 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 |
Maybe they added another intermediate step (like Creteil did)? In that case you'll need to reverse engineer it in Chrome Browser Console and modify the script. Good luck!
Hello. First of all thank you for adding this script. I am a complete beginner. How do you use this script? Is there a step by step tutorial that I can follow to apply it? Thank you
Sorry, there is no support other than the README on top of the script
Hello, thank you so much for this help.
I use Windows so can you tell me how to make work this script on Windows ? I read on top of the script that i mush put in my email but i don't understand where should i do ? :( Thank you so much. Have a nice day.
It should work on Windows okay, e.g. in git bash/msys or wsl environment. Besides that, I don’t develop or support this script anymore. If it doesn’t work, you’d need to fix it yourself. Good luck!
PlEASE I didn't get what is : SENDGRID_BEARER_TOKEN='' # should start with "SG."
How can I get it ?
Thank you so much for helping
It's a token to use SendGrid email sending API. You'll have to google "SendGrid bearer token" and how to get it. I don't provide any support for using this script.
OK, thank you anyway :)
Hello, this works perfectly, thank you again.
Would it possible please to have a similar script to take an appointment for "ECHANGE DE PERMIS DE CONDUIRE ÉTRANGER DÉLIVRÉ HORS UE ET EEE - PRÉFECTURE DE NANTERRE"?
It would be kind of you and you would be very helpful. Thanks a lot
EXCHANGE OF FOREIGN DRIVING LICENSE ISSUED OUTSIDE THE EU AND EEA - NANTERRE PREFECTURE
It is possible to adapt this script for this purpose, but I won't do it. I don't support or develop this script anymore.
You'll have to do it yourself. Good luck!
(version française ci-dessous)
Hi there,
Simply to tell everybody that I'm maintaining a tool for monitoring appointment availability in all prefectures (prefmon), tool which results are available online at aguichetsfermes.lacimade.org. Most of the work is keeping the appointment list up to date, so any help would be appreciated.
Thanks !
Salut,
Juste pour signaler que j'assure la maintenance d'un outil qui surveille la disponibilité des rdv dans toutes les préfectures (prefmon), outil dont les résultats sont visibles à l'adresse aguichetsfermes.lacimade.org. Le gros du travail, c'est maintenir la liste des procédures à jour, toute aide est la bienvenue.
Merci !
(version française ci-dessous)
Hi there,Simply to tell everybody that I'm maintaining a tool for monitoring appointment availability in all prefectures (prefmon), tool which results are available online at aguichetsfermes.lacimade.org. Most of the work is keeping the appointment list up to date, so any help would be appreciated.
Thanks !
Salut,
Juste pour signaler que j'assure la maintenance d'un outil qui surveille la disponibilité des rdv dans toutes les préfectures (prefmon), outil dont les résultats sont visibles à l'adresse aguichetsfermes.lacimade.org. Le gros du travail, c'est maintenir la liste des procédures à jour, toute aide est la bienvenue.
Merci !
Hello, je peux aider
Hello, je peux aider
Merci ! Peux-tu me contacter par mail ? (samuel point bizien arobase laposte point net).
PlEASE I didn't get what is : SENDGRID_BEARER_TOKEN='' # should start with "SG."
How can I get it ?
Thank you so much for helping
You either should have sendrid token or twilio. For Twilio, you can have a trial account from here: https://www.twilio.com/
The urls should be https not http. In case, you set it http, the script doesn't function correctly.
For one who needs I just right now made a bash script based on this GIST to check when planning for titre de séjours are ready. This is a little complex since there is an intermediate page with different guichets. https://gist.github.com/Lecrapouille/f11d541f435dbbba9ccccde86ab2d0dd Use with care since I have just written it and not yet fully tested. Beware also I do not know if we can be banned but contrary to this current script I sleep random 20 - 30 minutes before retrying. You have to set your phone number in the script, you'll receive up to 1 SMS by day thanks to https://textbelt.com when plannings are opened.
For avoiding banning, I recommend spinning several Amazon EC2 Paris microinstances
@vadimkantorov why looping the main loop every 300 s ? This makes their servers slow down, not nice for other people
Because you must be this fast for booking an appointment for naturalisation. Otherwise someone else takes it.
@vadimkantorov have you succeeded to do the "click" on the planning to reserve a day ? Look like not to me
No, I haven't tried doing that, that would be the best, getting these rdv to do any testing was almost impossible
So if you do that, that's a big improvement!
Depuis le covid, les prises de rendez-vous pour déposer les papiers sont plus humaines : les plannings sont ouverts pour les 2 semaines suivantes. Donc je n'ai pas eu de soucis. Par contre, pour récupérer le titre ça semble à nouveau être la misère d'où mon script. Dès que j'aurais le rendez-vous, je pourrais tester plus facilement.
Salut lecrapouille. j'aurai besoin d'adapter ce script pour la préfecture de melun. Suffirait il de ne modifier que l'url pour la faire correspondre a celle de melun ?
@gleek77 tu n'es pas sur mon gist, le mien est en bash. Et je ne suis pas sûr de pouvoir t'aider, car 1/ je n'ai pas retesté depuis et je sais qu'il y avait des bugs (sms), les liens ont dû totalement changés 2/ la pref me donne des boutons donc ce n'est pas une partie de plaisir que de coder ce genre de truc les soirs 3/ je ne suis pas webdev donc pas mon domaine. Ce qu'il faut faire c'est d'expérimenter le soir après 20h avec un browser ouvert en mode debug (F12) et voir les trames qui passent.
@gleek77 T'es au fait sur mon gist (qui est aussi en bash) :) Pour le reste, je suis d'accord avec @Lecrapouille, étudie dans Dev Console -> Network des paquets et ajoute des modifs si nécessaire. En plus, mon script ne sait pas "choisir" le service (qui est obligatoire pour Créteil, par exemple) ou prendre le rdv en autonomie complète.
Re. je vais voir si j'arrive à quelque chose . jsuis en terre inconnue
Thanks