ESC

Click the "allow" button if you want to receive important news and updates from immigrationboards.com


Immigrationboards.com: Immigration, work visa and work permit discussion board

Welcome to immigrationboards.com!

Login Register Do not show

Tracking TNT Passport Delivery

A section for posts relating to applications for Naturalisation or Registration as a British Citizen. Naturalisation

Moderators: Casa, archigabe, CR001, push, JAJ, ca.funke, Amber, zimba, vinny, Obie, EUsmileWEallsmile, batleykhan, meself2, geriatrix, John, ChetanOjha

Locked
digitaldrifta
Newly Registered
Posts: 24
Joined: Mon Feb 14, 2022 3:47 pm
South Africa

Tracking TNT Passport Delivery

Post by digitaldrifta » Thu Mar 16, 2023 10:41 am

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.

digitaldrifta
Newly Registered
Posts: 24
Joined: Mon Feb 14, 2022 3:47 pm
South Africa

Re: Tracking TNT Passport Delivery

Post by digitaldrifta » 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.

Newbritish
Newly Registered
Posts: 23
Joined: Thu Mar 02, 2023 12:26 pm
United Kingdom

Re: Tracking TNT Passport Delivery

Post by Newbritish » Thu Mar 16, 2023 11:10 am

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 …

meself2
Moderator
Posts: 3727
Joined: Mon Sep 06, 2021 5:10 pm
Ireland

Re: Tracking TNT Passport Delivery

Post by meself2 » Thu Mar 16, 2023 11:14 am

WSL should probably work as well, since Mac is a *nix type system.
Not a qualified immigration adviser. Use links and references given to gain confirmation and/or extra information.

digitaldrifta
Newly Registered
Posts: 24
Joined: Mon Feb 14, 2022 3:47 pm
South Africa

Re: Tracking TNT Passport Delivery

Post by digitaldrifta » Thu Mar 16, 2023 11:38 am

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)

digitaldrifta
Newly Registered
Posts: 24
Joined: Mon Feb 14, 2022 3:47 pm
South Africa

Re: Tracking TNT Passport Delivery

Post by digitaldrifta » Thu Mar 16, 2023 1:28 pm

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".

Locked