Skip to content

Instantly share code, notes, and snippets.

@kidager
Created May 13, 2021 17:11
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 kidager/cc63ae00f38eb8497a2e1cb775c84aac to your computer and use it in GitHub Desktop.
Save kidager/cc63ae00f38eb8497a2e1cb775c84aac to your computer and use it in GitHub Desktop.
look-for-rdv.sh
#!/bin/bash
# Install
# >>> sudo apt-get install jq procps xdg-utils
# Run
# >>> watch -d --color --interval 5 --exec ./look-for-rdv.sh
# Logs
# >>> tail -f requests.log
if ! command -v jq &> /dev/null; then
echo "jq could not be found, run: sudo apt-get install jq"
exit 1;
fi
# Put Cookie here
COOKIE="__COOKIE__"; # or not :p
# Put CSRF Token here
CSRF_TOKEN="__CSRF_TOKEN__"; # or not :p
TIME=$(date +%T);
declare -A API_URLS;
API_URLS=(
["Asnieres-Sur-Seine"]="https://www.doctolib.fr/search_results/2541270.json?ref_visit_motive_id=6970&ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&speciality_id=5494&search_result_format=json&force_max_limit=2&time=${TIME}"
["Maisons-Laffitte"]="https://www.doctolib.fr/search_results/2540781.json?ref_visit_motive_id=6970&ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&speciality_id=5494&search_result_format=json&force_max_limit=2&time=${TIME}"
["Courbevoie"]="https://www.doctolib.fr/search_results/3572386.json?ref_visit_motive_id=6970&ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&speciality_id=5494&search_result_format=json&force_max_limit=2&time=${TIME}"
["Argenteuil"]="https://www.doctolib.fr/search_results/3569304.json?ref_visit_motive_id=6970&ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&speciality_id=5494&search_result_format=json&force_max_limit=2&time=${TIME}"
["Paris"]="https://www.doctolib.fr/search_results/3574128.json?ref_visit_motive_id=6970&ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&speciality_id=5494&search_result_format=json&force_max_limit=2&time=${TIME}"
["Suresnes"]="https://www.doctolib.fr/search_results/3573857.json?ref_visit_motive_id=6970&ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005&speciality_id=5494&search_result_format=json&force_max_limit=2&time=${TIME}"
);
for KEY in "${!API_URLS[@]}"; do
API_URL="${API_URLS[${KEY}]}";
JSON_CONTENT=$(curl --silent \
-H "authority: www.doctolib.fr" \
-H "pragma: no-cache" \
-H "cache-control: no-cache" \
-H "content-type: application/json; charset=utf-8" \
-H "accept: application/json" \
-H "dnt: 1" \
-H "x-csrf-token: ${CSRF_TOKEN}" \
-H "sec-fetch-site: same-origin" \
-H "sec-fetch-mode: cors" \
-H "sec-fetch-dest: empty" \
-H "referer: https://www.doctolib.fr/vaccination-covid-19/ile-de-france-asnieres-sur-seine-avenue-des-cerisiers?force_max_limit=2&ref_visit_motive_id=6970&ref_visit_motive_ids[]=6970&ref_visit_motive_ids[]=7005" \
-H "accept-language: en-GB,en-US;q=0.9,en;q=0.8,fr-FR;q=0.7,fr;q=0.6,ar-TN;q=0.5,ar;q=0.4" \
-H "cookie: $COOKIE" \
"$API_URL" \
);
{
echo "=========================";
echo "[$(date +%F) $(date +%T)] ${KEY}";
echo "${JSON_CONTENT}";
echo "=========================";
} >> requests.log
TOTAL=$(echo "${JSON_CONTENT}" | jq '.total');
if [[ 0 -ne $TOTAL ]]; then
DATES=$(echo "${JSON_CONTENT}" | jq -rc '.availabilities | map(select((.slots | length) > 0)) | map(.date) | join("|")')
AVAILABLE_DATES="";
[[ "$(date +%F)" =~ ^(${DATES})$ ]] && AVAILABLE_DATES="$(date +%F) ${AVAILABLE_DATES}";
[[ "$(date -d "tomorrow" +%F)" =~ ^(${DATES})$ ]] && AVAILABLE_DATES="$(date -d "tomorrow" +%F) ${AVAILABLE_DATES}";
if [[ -z "${AVAILABLE_DATES// }" ]]; then
echo "${KEY} : No RDV availables";
else
echo "${KEY} : Available dates:";
echo "${AVAILABLE_DATES}";
echo "================";
URL="https://www.doctolib.fr$(echo "${JSON_CONTENT}" | jq -rc '.search_result.url')";
echo "Center : $(echo "${JSON_CONTENT}" | jq -rc '.search_result.name_with_title')";
echo "Address : $(echo "${JSON_CONTENT}" | jq -rc '.search_result | "\(.address), \(.city) \(.zipcode)"')";
echo "Maps : $(echo "${JSON_CONTENT}" | jq -rc '.search_result.position | "https://maps.google.com/?q=\(.lat),\(.lng)"')";
echo "URL : $URL";
echo "================";
xdg-open "$URL" > /dev/null;
fi
else
echo "${KEY} : No RDV availables";
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment