Skip to content

Instantly share code, notes, and snippets.

@lg
Created December 25, 2021 22:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lg/225b04f8f8484906603a83928c82ee05 to your computer and use it in GitHub Desktop.
Save lg/225b04f8f8484906603a83928c82ee05 to your computer and use it in GitHub Desktop.
Checks all Shoppers Drug Marts for if they have COVID antigen tests available on a specific day
# make sure to change:
# '2021-12-25' to the date you're looking for, and
# '45.000000; -75.11111' to your latitude and longitude
# '100' to the amount of km thats max for your roadtrip out to get tested
# curl command taken from https://shoppersdrugmart.medmeapp.com/schedule/groups/Covid-19-Rapid-Screening (and removed the x-pharmacyid header)
curl 'https://gql.medscheck.medmeapp.com/graphql' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H 'Authorization: ' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Host: gql.medscheck.medmeapp.com' \
-H 'Origin: https://shoppersdrugmart.medmeapp.com' \
-H 'Content-Length: 1039' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15' \
-H 'Referer: https://shoppersdrugmart.medmeapp.com/' \
-H 'Connection: keep-alive' \
-H 'x-tenantid: edfbb1a3-aca2-4ee4-bbbb-9237237736c4' \
--data-binary '{"operationName":"publicGetEnterprisePharmacies","variables":{"appointmentTypeName":"Asymptomatic COVID-19 Rapid Antigen Screening","enterpriseName":"SDM"},"query":"query publicGetEnterprisePharmacies($appointmentTypeName: String, $enterpriseName: String!, $storeNo: String) {\n publicGetEnterprisePharmacies(appointmentTypeName: $appointmentTypeName, enterpriseName: $enterpriseName, storeNo: $storeNo) {\n id\n name\n timeZone\n enterprise\n theme\n logoLong\n logoCircle\n logoLongInverse\n province\n storeNo\n pharmacyAddress {\n id\n unit\n streetNumber\n streetName\n city\n province\n country\n postalCode\n poBox\n longitude\n latitude\n __typename\n }\n pharmacyContact {\n id\n phone\n email\n __typename\n }\n appointmentTypes {\n id\n isWalkinAllowed\n isWaitlisted\n bookingStartDate\n bookingEndDate\n waitlistCount\n __typename\n }\n __typename\n }\n}\n"}' |
jq '
# from https://rosettacode.org/wiki/Haversine_formula#jq
def haversine(lat1;lon1; lat2;lon2):
def radians: . * (1|atan)/45;
def sind: radians|sin;
def cosd: radians|cos;
def sq: . * .;
(((lat2 - lat1)/2) | sind | sq) as $dlat
| (((lon2 - lon1)/2) | sind | sq) as $dlon
| 2 * 6372.8 * (( $dlat + (lat1|cosd) * (lat2|cosd) * $dlon ) | sqrt | asin) ;
[
.data.publicGetEnterprisePharmacies[] |
select(.appointmentTypes[].bookingStartDate?[0:10] == "2021-12-25") |
def dist: haversine(.pharmacyAddress.latitude | tonumber; .pharmacyAddress.longitude | tonumber; 45.000000; -75.11111) ;
select(dist < 100) |
{
name: .name,
address: .pharmacyAddress.city,
date: .appointmentTypes[].bookingStartDate,
distance: dist
}
] |
sort_by(.distance)'
# example output:
# [
# {
# "name": "SHOPPERS DRUG MART River & Earl Armstrong",
# "address": "Ottawa",
# "date": "2021-12-25",
# "distance": 3.605105867939924
# },
# {
# "name": "SHOPPERS DRUG MART Bank & Findlay",
# "address": "Ottawa",
# "date": "2021-12-25",
# "distance": 7.848609266189158
# },
# {
# "name": "SHOPPERS DRUG MART Montreal Road",
# "address": "Ottawa",
# "date": "2021-12-25",
# "distance": 12.440489145090158
# }
# ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment