Last active
June 16, 2021 13:14
-
-
Save pp5x/58e864598b60f6d3650c5ab5e769a6a4 to your computer and use it in GitHub Desktop.
Search vaccine availabilities for next 24 hours
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env bash | |
| ############################################################################## | |
| # Usage: ./covid.sh | |
| # Checks COVID-19 vaccine slots on Doctolib every 5-15 seconds. | |
| # If you want to keep the Mac awake: caffeinate ./covid.sh | |
| # | |
| # Stop the script with Ctrl-C | |
| # | |
| # When the script found a slot it will wait 1min 30 before proceeding to next | |
| # center. | |
| # | |
| # Dependencies | |
| # ------------ | |
| # | |
| # macOS (Homebrew): brew install jq | |
| ############################################################################## | |
| ################# | |
| # Configuration # | |
| ################# | |
| # List of URLs to check (transactions from Developer - Web inspection - Network tab). | |
| urls=( | |
| "&visit_motive_ids=2823401&agenda_ids=473228-473231-473227-467191-467179-467178-467162-467152-467164-467155-467153-467186-473230-473226-473223-467151-467154-467177-467189-467190-467150-467167-473225-467166-467174-467165-473232-467163-467175-467176-467188-467187&insurance_sector=public&practice_ids=185273&destroy_temporary=true&limit=2" | |
| "&visit_motive_ids=2735278&agenda_ids=472647-472653-447491-447376-447377-447378-447388-447389-447391-447375-447373-447381-447384-447385-447492-472652-447380-447390-472655-447383-447490-472658-469829-470547-470548-470549-469823-469824-469825-469827-469831-469836&insurance_sector=public&practice_ids=179894&destroy_temporary=true&limit=2" | |
| ) | |
| # Same order as for URLS, message to display a friendly location. | |
| messages=( | |
| "Porte de Versailles" | |
| "Stade de France - Saint Denis" | |
| ) | |
| # Website to load when slots are found. | |
| redirects=( | |
| "https://partners.doctolib.fr/centre-de-sante/paris/vaccinodrome-covid-19-porte-de-versailles?pid=practice-185273" | |
| "https://partners.doctolib.fr/centre-de-sante/saint-denis/centre-de-vaccination-covid-19-stade-de-france?highlight%5Bspeciality_ids%5D%5B%5D=5494" | |
| ) | |
| ################## | |
| # Implementation # | |
| ################## | |
| function getUrl () { | |
| startUrl="https://partners.doctolib.fr/availabilities.json\?start_date=" | |
| date=$(date +"%Y-%m-%d") | |
| url="${startUrl}${date}${url}" | |
| } | |
| total_slots=0 | |
| function isAvailable () { | |
| local results="" | |
| if ! results=$(curl -s "$url") | |
| then | |
| echo 'error with curl' >&2 | |
| return 1 | |
| fi | |
| # Print JSON query for further investigation. | |
| echo "$results" >&2 | |
| total_slots=$(jq '.total' <<< "$results") | |
| if [[ $total_slots == 0 ]]; then | |
| return 1 | |
| fi | |
| return 0 | |
| } | |
| # Stop this script with Ctrl-C ! | |
| while true | |
| do | |
| cat <<EOF >&2 | |
| $(tput setaf 3) | |
| -- Stop the script with Ctrl-C. | |
| -- Run with caffeinate to keep the Mac awake: caffeinate $0 | |
| $(tput sgr0) | |
| EOF | |
| validCounter=0 | |
| for i in "${!urls[@]}" | |
| do | |
| cat <<EOF >&2 | |
| Checking $(tput setaf 5)${messages[$i]}$(tput sgr0) ... | |
| EOF | |
| url="${urls[$i]}" | |
| # Format $url with current date | |
| getUrl $url | |
| if isAvailable | |
| then | |
| osascript -e "display notification \"RDV disponibles: $total_slots\" with title \"${messages[$i]}\"" | |
| open -a Safari "${redirects[$i]}" | |
| afplay /System/Library/Sounds/Funk.aiff | |
| say "Found $total_slots slots in ${messages[$i]}" | |
| cat <<EOF >&2 | |
| Found $(tput setaf 1)$total_slots$(tput sgr0) slots! | |
| Waiting 90 seconds before next check. | |
| EOF | |
| # Wait 1 minute 30s before checking again. Leave time to the user to | |
| # checkout the available appointments. | |
| sleep 90 | |
| continue | |
| fi | |
| # Wait between 5-15 seconds until next query to not flood Doctolib's servers. | |
| sleep $(( ( RANDOM % 10 ) + 5 )) | |
| (( counter++ )) || true | |
| echo "$counter" >&2 | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
😄 👍 Bon, j'espère que tout s'est bien passé et que tu as pu trouver tes rendez-vous maintenant :-)