Dominos Tracker API

I wanted a way to send myself a text message when Dominos was “Out the Door”. It turns out they have an XML API, so I did poor-man’s BASH parsing and run this periodically to have it send me a message.

#!/bin/bash
###################################
# Dominos Pizza Tracker
###NO ORDER:
#
#
### Timestamps:
#StartTime
#- OrderStatus "Order Placed" ????
#- OrderStatus Prep ????
#MakeTimeSecs
#- OrderStatus Bake
#OvenTime
#- OrderStatus Routing Station
#RackTime
#- OrderStatus Out the Door
#RouteTime
#- OrderStatus Delivered
#DeliveryTIme
#- OrderStatus Complete

if [[ "$DEBUG" != "" ]] ; then set -x ; fi

### Variables
PHONES="PUT YOUR PHONE NUMBERS HERE, SPACE SEPARATED"
EMAIL="PUT YOUR EMAIL HERE"  # For all status changes
SMS="SMS EMAIL HERE" # For delivery notices
FREQUENCY=PUT YOUR CRON POLLING FREQUENCY IN SECONDS HERE

### Make a temp file to save query costs
LOG=/tmp/$$.dominos
rm $LOG >/dev/null 2>&1 
touch $LOG

### Use phone number to get order
for PHONE in $PHONES ; do
	lynx -dump http://trkweb.dominos.com/orderstorage/GetTrackerData?Phone=$PHONE > $LOG
	
	### Do we even have an order?
	NOORDER=`grep '' $LOG`
	if [[ -n ${NOORDER} ]] ; then
		echo DOMINOS: NO ORDERS for $PHONE
		continue
	fi
	
	### Collect info we might need
	STATUS=`grep '.[A-Za-z]*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	STARTTIME=`grep '.*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	OVENTIME=`grep '.*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	RACKTIME=`grep '.*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	ROUTETIME=`grep '.*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	DELIVERYTIME=`grep '.*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	LASTTIME=`grep 'Time>.* | cut -f 1 -d \< | tail -1`
	ORDERKEY=`grep '.*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	ORDERDESCRIPTION=`grep '.*' $LOG | cut -f 2 -d \> | cut -f 1 -d \< `
	
	### See how long ago was our status
	NOW=`date +%s`
	LAST=`date -d "$LASTTIME" +%s`
	(( DIFF = $NOW - $LAST ))

	echo DOMINOS: Order $ORDERKEY for $PHONE placed at $STARTTIME and last status of $STATUS at $LASTTIME

	### If less than 3 mins and 3 seconds, we report
	if [[ ${DIFF} -lt ${FREQUENCY} ]] ; then
		case $STATUS in
		"Delivered"|"Out the Door")
			cat $LOG | mail -vs "Dominos $STATUS for $PHONE at $STARTTIME" $EMAIL,$SMS
			;;
		*)
			cat $LOG | mail -vs "Dominos $STATUS for $PHONE at $STARTTIME" $EMAIL
			;;
		esac
	fi
done

Comments are closed.