All you need is a Mac, any terminal (I use iterm2) and jq installed.
Update below with your postcode and your reference number (without PEX)
Save as a .sh file and run.
It will query the API every 60 seconds, if the latest scan's co-ordinates are different, it will open a Chrome window showing where it was scanned on google maps.
Code: Select all
#!/bin/bash
postcode="XXXXXX"
ref="XXXXXXXXX"
last_url=""
while true
do
# Fetch JSON from TNT tracking API and extract latest scan's location as Google Maps URL
url=$(curl -s "https://delivery.tnt.com/consignment-svc/api/v1/consignments/tracking?postcode=$postcode&pan=$ref" | jq -r '.[].stops[].scans[-1].location | "https://www.google.com/maps/search/" + (.latitude | tostring) + "," + (.longitude | tostring)')
# Open Google Maps URL in Chrome if different from last URL
if [[ "$url" != "$last_url" ]]; then
open -a "Google Chrome" "$url"
last_url="$url"
fi
sleep 60
done
