Skip to content

Instantly share code, notes, and snippets.

@nickrw
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save nickrw/3359da49c2c0e2fafb71 to your computer and use it in GitHub Desktop.

Select an option

Save nickrw/3359da49c2c0e2fafb71 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Debian package dependencies: html-xml-utils qprint w3m
parcel=$1
from=$2
to=$3
tmp=/tmp/parcelforce_$parcel
html_table=$(curl -s "http://www.parcelforce.com/track-trace?page_type=parcel-tracking-details&parcel_number=$parcel" | hxselect '.sticky-enabled')
echo "$html_table" > $tmp.new
diff -q $tmp.new $tmp > /dev/null 2>&1
diffrc=$?
if [[ $diffrc -eq 0 ]]; then
echo "No change since last run"
exit 0
fi
cp $tmp.new $tmp
plain_table=$(echo "$html_table" | w3m -T text/html -dump -cols 100)
qp_plain_table=$(echo "$plain_table" | qprint -e )
qp_html_table=$(echo "$html_table" | qprint -e )
latest_status=$(echo $html_table | hxselect -c 'tr:first-child td:nth-child(4)')
qp_html_latest_status=$(echo "<h3>Latest status: <b>$latest_status</b></h3>" | qprint -e)
qp_plain_latest_status=$(echo "Latest status: $latest_status" | qprint -e)
echo "Changed! New state $latest_status"
echo "Sending email to $to"
cat <<EOF | sendmail -f $from -t $to
From: $from
To: $to
Subject: Parcelforce $parcel: $latest_status
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_6416024_1978353709.1399388266020"
------=_Part_6416024_1978353709.1399388266020
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
$qp_plain_latest_status
$qp_plain_table
------=_Part_6416024_1978353709.1399388266020
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<body>
$qp_html_latest_status
$qp_html_table
</body>
</html>
------=_Part_6416024_1978353709.1399388266020--
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment