Continuing With The Automation Theme

So I pre-ordered my Samsung S7 from Samsung last week. They didn't give me much of a timeline of when I can expect things to happen but I have been keeping an eye on the tracking page for any change.

Order Tracking Page

But then I thought, "What if I could get the computer to check this page for me and alert me the second it changes?" Probably Samsung will send and e-mail when it does change but I would like to keep an eye on this screen.

So I started with a little Bash script:

#!/bin/bash

count=`curl -s "XXXXXXXXX" | grep -c "Not Processed"`

if [ "$count" = "0" ]
then

fi

I have censored out the URLs with "XXX", just in case. But the first line basically does a curl request to the tracking URL and then counts the instances of the words "Not Processed" - which at the moment is just the 1.

If the count is 0, it means something is changed!

The next challenge is how to alert me. Well, we use Slack in the office. So I made an incoming webhook that can be sent things using curl:

  curl -X POST --data-urlencode 'payload={"channel": "#channel", "username": "Samsung phone alert", "text": "<@antony.dandrea> something has changed on your order! Check here: <XXXXXXX>", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/XXXXXXXXXXXXX

Finally, I stuck it into a CRON job to run every minute:

crontab -e

and then added:

*  *   *   *   *   /path/to/is_my_phone_processed_yet.sh 

Done.

So when the status changes from "Not Processed", I will get an alert on Slack within 1 minute (would be interesting to see if Samsung alerts me of such a change and if I beat it). Of course we could improve this to alerting me when there is any change at all (for future statuses).


© 2012-2017