iPhone 6 Stock Checker with Azure

If it has passed you by in the past week, the iPhone 6 has been released
and demand has been high.  There are currently stock shortages in most
parts of the world, especially with the iPhone 6 Plus.

Apple provide a handy stock checking tool, where you can enter what
phone you want and what store to check and it will tell you what stock
is available.  I found I was checking this a few times a day, checking
the stock in the Sydney area. 

So…. I decided to automate it….. with Azure!

NB. I wrote this program in about 30 minutes and is not polished code.  This post is not about the code particularly.  If it is requested, I will share the code.

Getting started

I started by reverse engineering the page on the apple site.  It makes a
couple of requests which return JSON.  The first request is getting a
list of stores and the second request is to get the availability in each
store.  The good news is that Apple have not locked down these requests
to their own domains so anyone can make these requests and get the
response.

I wrote a small console application which works as follows:

  • Download Stores
  • Download Availability
  • Loop through the stores I am interested in
  • Check availability of all iPhone 6 and 6 Plus
  • If there is stock available, send myself a text message listing the stores and the devices in stock.

SMS Alerts

I am using clickatell for this.  I have used them previously and have an
account setup.  This was part was as painless as making an HTTP Request
to the Clickatell endpoint.  Then a few seconds later, the SMS appears!

Scheduling

I started by setting up a scheduled task on my computer and getting it
to run every 5 mins.  This worked well, but then I thought about Azure
WebJobs
WebJobs are a system that allows you to run programs or
scripts in one of three ways: on demand, continuously or on a schedule.
WebJobs are connected to Azure WebSites so I created a dummy website in order to house my WebJob. 

Creating the WebJob was very simple through the Azure Portal.

CreateWebJob

Before you can create a WebJob you need to create a zip file which
contains your exe and all it’s dependencies.  Then choose a Name and
How to run. I chose to run this on a 5 minute schedule.

Now I have the power of a Microsoft data center running my little
program to check on iPhone stock levels.

Azure provide a logging feature where you can see the results of your
jobs, which is really very nice.  Here is a screenshot of what the
overall logging of my job looks like.

WebJobsLogging

And now the detail of one of the executions.

JobOutput

The output shown above is the captured console output from the original
application, but it is extremely useful for debugging and testing
purposes.

Conclusion

Leveraging Azure WebJobs was extremely simple.  I was able to upload my
console application in a matter of minutes and have it run reliably from
Azure.

Now…. Just waiting to get the text message…..