Figuring out iPhone Availability at all stores and at all hours

Apple has an availability web page that works between the hours if 9:00pm and 9:00am. Outside those hours, it doesn’t work. That’s silly. I figured out what the flash was doing behind the scenes. It’s quite easy. By fetching the web page, and then parsing the output, you can simply look for stores that have the phone (which is a shorter list at the time of this writing.

The first thing you have to do is fetch the availability information. The URL is:

http://www.apple.com/retail/iphone/feeds/iphone_inv.json?z=1

Now, the flash widget that Apple sends you will change that z parameter. But it’s unnecessary. z=1 is fine. The file you get is a large-ish (18K) JSON file. The first few lines look like this:

{"date":"Thu, 05 Jul 2007 00:00:00 -0700","states":{"AL":[{"name":"The Summit","storeid":"R225","city":"Birmingham","url":"/retail/thesummit/","available":false}],
AZ":[{"name":"Chandler Fashion Center","storeid":"R026","city":"Chandler","url":"/retail/chandler/","available":false},{"name":"Biltmore","storeid":"R031","city":"Phoenix","url":"/retail/biltmore/","available":false},{"name":"La Encantada","storeid":"R086","city":"Tucson","url":"/retail/laencantada/","available":false}],
CA":[{"name":"Glendale Galleria","storeid":"R001","city":"Glendale","url":"/retail/glendale/","available":false},{"name":"Palo Alto","storeid":"R002","city":"Palo lto","url":"/retail/paloalto/","available":false},
{"name":"South Coast Plaza","storeid":"R004","city":"Costa Mesa","url":"/retail/southcoastplaza/","available":false},{"name":"Walnut Creek","storeid":"R014","city":"Walnut Creek","url":"/retail/walnutcreek/","available":false},

Notice the “available”:false in there. That tells you that the store doesn’t have it. So, I do a quick perl search and replace, replacing open curly braces with a new-line character. Then I grep for “available”:true and finally print out the store name and city where it’s available.

The command, which will work fine on MacOS X, Linux, FreeBSD, or Windows (if you have Cygwin and curl installed), looks like this:

curl -s 'http://www.apple.com/retail/iphone/feeds/iphone_inv.json?z=-1' |
  perl -p -e 's,{,n,g' |
  grep 'available":true' |
  cut -d , -f 1,3

The output, on July 5th 2007, looks like this:

"name":"Bridgeport Village","city":"Tigard"
"name":"Shadyside","city":"Pittsburgh"

Looks like only 2 stores have it today.

Comments aren't enabled for this post.