Skip to content

Instantly share code, notes, and snippets.

@benjeffery
Last active January 28, 2021 12:28
Show Gist options
  • Save benjeffery/7c2943634d4e02bbad882fb679bfb450 to your computer and use it in GitHub Desktop.
Save benjeffery/7c2943634d4e02bbad882fb679bfb450 to your computer and use it in GitHub Desktop.
UK Covid testing alarm
import datetime
import time
import requests
import playsound #You might need to install pygobject if you get an error about missing "gi" module for this.
playsound.playsound("ding.mp3") #You'll need a file here that is noisy
while True:
try:
r = requests.post(
"https://ads-prd-gov-1-sp.test-for-coronavirus.service.gov.uk/testcentres/availabilityquery",
headers={
"authority": "ads-prd-gov-1-sp.test-for-coronavirus.service.gov.uk",
"accept": "application/json, text/plain, */*",
"dnt": "1",
"x-urlcode": "***GET THIS IN BROWSER DEV TOOLS FROM A REQUEST MADE BY THE WEBSITE***",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36",
"content-type": "application/json",
"origin": "https://test-for-coronavirus.service.gov.uk",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "https://test-for-coronavirus.service.gov.uk/",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
},
json={
"topLevelTestCentreId": "CVD19",
"postcode": "***YOUR_POSTCODE***",
"testCentreGroupIds": ["GR_RTS", "GR_STS", "GR_MTU", "GR_LTS"],
"startDate": "** DATE IN THIS FORMAT : 2020-09-10T00:00:00**",
"numberOfDays": 5,
"appointmentTypeCode": "ATCOM05",
"paging": {"currentPage": 1, "pageSize": 3},
},
).json()
print("Time:", datetime.datetime.now())
if len(r["testCentres"]) == 0:
print("Nothing!")
for c in r["testCentres"]:
print(
c["testCentre"]["displayName"],
c["geolocation"]["distance"],
c["availability"]["availableSlots"],
)
if float(c["geolocation"]["distance"]) < 50:
for i in range(20):
playsound.playsound("ding.mp3")
except:
playsound.playsound("ding.mp3")
time.sleep(60)
# Example request and response from chrome dev tools:
# curl 'https://ads-prd-gov-1-sp.test-for-coronavirus.service.gov.uk/testcentres/availabilityquery' \
# -H 'authority: ads-prd-gov-1-sp.test-for-coronavirus.service.gov.uk' \
# -H 'accept: application/json, text/plain, */*' \
# -H 'dnt: 1' \
# -H 'x-urlcode: YOUR_CODE_HERE' \
# -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36' \
# -H 'content-type: application/json' \
# -H 'origin: https://test-for-coronavirus.service.gov.uk' \
# -H 'sec-fetch-site: same-site' \
# -H 'sec-fetch-mode: cors' \
# -H 'sec-fetch-dest: empty' \
# -H 'referer: https://test-for-coronavirus.service.gov.uk/' \
# -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
# --data-binary '{"topLevelTestCentreId":"CVD19","postcode":"YOUR_POSTCODE","testCentreGroupIds":["GR_RTS","GR_STS","GR_MTU"],"startDate":"2020-09-10T00:00:00","numberOfDays":5,"appointmentTypeCode":"ATCOM05","paging":{"currentPage":1,"pageSize":3}}' \
# --compressed
# {
# "testCentres": [
# {
# "availability": {
# "availableSlots": 3,
# "slotsAvailableOn": ["2020-09-11T00:00:00"],
# },
# "geolocation": {"distance": 113.036529084286},
# "testCentre": {
# "testCentreId": "LRC",
# "displayName": "Central Chester - Walk through site",
# "address": {
# "addressLine1": "Little Roodee Car Park",
# "town": "Chester",
# "postcode": "CH1 1SL",
# },
# "active": true,
# "testCentreGroupId": "GR_LTS",
# },
# },
# {
# "availability": {
# "availableSlots": 7,
# "slotsAvailableOn": ["2020-09-11T00:00:00"],
# },
# "geolocation": {"distance": 130.744753751102},
# "testCentre": {
# "testCentreId": "KNH",
# "displayName": "Kirklees Ravensthorpe - Walk through site",
# "address": {
# "addressLine1": "Kirklees Neighbourhood Housing Car Park, Queen Street",
# "town": "Ravensthorpe",
# "postcode": "WF13 3BT",
# },
# "active": true,
# "testCentreGroupId": "GR_LTS",
# },
# },
# {
# "availability": {
# "availableSlots": 1,
# "slotsAvailableOn": ["2020-09-11T00:00:00"],
# },
# "geolocation": {"distance": 134.594445459396},
# "testCentre": {
# "testCentreId": "CAL",
# "displayName": "Halifax Calderdale - Walk through site",
# "address": {
# "addressLine1": "Overflow Car Park, ASDA Halifax Superstore, Thrum Hall Lane",
# "town": "Halifax",
# "postcode": "HX1 4PG",
# },
# "active": true,
# "testCentreGroupId": "GR_LTS",
# },
# },
# ],
# "flagInvalidGeoLocation": false,
# "customerCode": "XXXXXXX",
# }
@wywywywy
Copy link

And test just came back negative 😁😁

@benjeffery
Copy link
Author

And test just came back negative

Yay! My daughters did too.

I keep thinking we should turn this script into a live website with current and historic availability.

@andy-thomason
Copy link

Thanks for this. We finally managed to get through but the nearest centre is in mid wales.

My wife tells me that PCR tests should cost pennies as there are 384 well machines. They could do 170 tests per run (4 hours).
Factor in the £10/hour postdoc to run it...

@andy-thomason
Copy link

Someone is making a lot of money by rationing the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment