Created
December 29, 2021 20:13
-
-
Save kirelagin/e318a50dd96df676982a6797dc2556b9 to your computer and use it in GitHub Desktop.
Find available appointments at Quest Diagnostics labs
This file contains 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 | |
# SPDX-FileCopyrightText: 2021 Kirill Elagin <https://kir.elagin.me/> | |
# SPDX-License-Identifier: CC0-1.0 | |
### | |
# | |
# Find available appointments at Quest Diagnostics labs. | |
# | |
# This quick-and-dirty script queries their appointment scheduling API | |
# and does some trivial processing to display the available slots. | |
# | |
# Unlike the official website, it queries appointments for a range of dates | |
# instead of just a single one. Also, the output is generally less noisy. | |
# On top of that, it turns out, their API gives current waiting time for | |
# each location, so it shows those too. | |
# | |
# Use: | |
# | |
# 1. Download this script. | |
# | |
# 2. Start scheduling an appointment on their website, proceed until the | |
# calendar view. Open Developer Tools in your web-browser and take note | |
# of the `facilityServiceId` that it sends – it will depend on what services | |
# you chose. Fill it in in the query below. | |
# (The currently pre-filled ones are for an employer drug test.) | |
# | |
# 3. Edit the “from” and “to” dates in the query below. Make sure the “from” | |
# date is not in the past (i.e. at least today). | |
# | |
# 4. Edit the geographic location in the query below. You can get the coordinates | |
# by right-clicking in Google Maps. | |
# | |
# 5. Run the script. | |
# | |
# Dependencies: | |
# | |
# * curl | |
# * jq | |
# | |
# e.g. `nix-shell -p curl jq` | |
### | |
query=$(cat<<EOF | |
{ | |
"facilityServiceId":[18,12], | |
"fromDate":"2021-12-29", | |
"toDate":"2022-01-05", | |
"latitude": 42.34519, | |
"longitude": -71.11076, | |
"miles":1, | |
"maxReturn":2, | |
"firstPscToReturn":0, | |
"filterForAvailability":false, | |
"includeWaitTime":true, | |
"onlyAvailableSlots":true | |
} | |
EOF | |
) | |
###################### | |
# Get some session cookie | |
cookies="/tmp/quest.cookies" | |
if [ ! -f "$cookies" ]; then | |
curl -s \ | |
-c "$cookies" \ | |
'https://appointment-beta.questdiagnostics.com/schedule-appointment/' \ | |
>/dev/null | |
fi | |
res=$(curl -s --fail-with-body \ | |
-b "$cookies" -b "CSRF-TOKEN=x" -H "X-CSRF-TOKEN: x" \ | |
-H 'Content-Type: application/json' -X POST --data "$query" \ | |
'https://appointment-beta.questdiagnostics.com/guest/getPscsWithAvailability' | |
) | |
if [ "$?" -ne 0 ]; then | |
printf 'Error (not 200): %s\n' "$res" >&2 | |
exit 1 | |
fi | |
jq_expr='.data[] | {name, waitTime, "avail": (.availability | map(select(.slots | length > 0) | {"date": .date, "slots": .slots | map(.time)}))}' | |
echo "$res" | jq "$jq_expr" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment