Page 1 of 1

Tracking TNT Passport Delivery

Posted: Thu Mar 16, 2023 10:41 am
by digitaldrifta
I'm a nerd so I wrote a bash script to monitor the progress of my passport delivery from TNT.
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
Use it or don't use it :D Someone may find it useful.

Re: Tracking TNT Passport Delivery

Posted: Thu Mar 16, 2023 10:53 am
by digitaldrifta
I can't seem to edit the first post. When you run the script initially it will open googlemaps to the most recent scan, for example when I open the script it takes me here: https://www.google.com/maps/search/51.3 ... 0.14445733

This looks like the Croydon TNT Depot.

Re: Tracking TNT Passport Delivery

Posted: Thu Mar 16, 2023 11:10 am
by Newbritish
digitaldrifta wrote:
Thu Mar 16, 2023 10:53 am
I can't seem to edit the first post. When you run the script initially it will open googlemaps to the most recent scan, for example when I open the script it takes me here: https://www.google.com/maps/search/51.3 ... 0.14445733

This looks like the Croydon TNT Depot.


Amazing!! Being a tech nerd pays off!

I don’t have a Mac and have no clue about using scripts/software programming etc. hhhh imagine if tnt or hmpo saw your post …

Re: Tracking TNT Passport Delivery

Posted: Thu Mar 16, 2023 11:14 am
by meself2
WSL should probably work as well, since Mac is a *nix type system.

Re: Tracking TNT Passport Delivery

Posted: Thu Mar 16, 2023 11:38 am
by digitaldrifta
Here's the python version that has the same functionality, save as .py and run with:
python3 script.py
You will need to have the requests library installed to run this script. You can install it with pip by running:

Code: Select all

pip install requests

Code: Select all

import requests
import webbrowser
import json
import time

postcode = "XXXXXX"
ref = "XXXXXXXXX"
last_url = ""

while True:
    # Fetch JSON from TNT tracking API and extract latest scan's location as Google Maps URL
    response = requests.get(f"https://delivery.tnt.com/consignment-svc/api/v1/consignments/tracking?postcode={postcode}&consignmentNumber=&pan={ref}")
    data = json.loads(response.text)
    url = f"https://www.google.com/maps/search/{data[0]['stops'][0]['scans'][-1]['location']['latitude']},{data[0]['stops'][0]['scans'][-1]['location']['longitude']}"

    # Open Google Maps URL in Chrome if different from last URL
    if url != last_url:
        webbrowser.get("chrome").open(url)
        last_url = url

    time.sleep(60)

Re: Tracking TNT Passport Delivery

Posted: Thu Mar 16, 2023 1:28 pm
by digitaldrifta
Haha so was busy working then suddenly chrome popped up with google maps with the location set to outside my house. Then I heard plop on the floor and realised my passport just been put through the door.

All seems well, no typos or "Official Observations".