My Twilio Inventory Checker
I recently decided that I want to start taking photography seriously. I just got married and we are actually pretty good friends with our photographers, so I got to talk to them about photography. Additionally, I started listening to the old episodes of The Talk Show podcast, specifically one where Dan and John talked to James Duncan Davidson and then Dan Benjamin’s podcast with James Duncan Davidson called Tack Sharp, so I’ve gotten a lot of exposure in a very short period of time to how cool photography can be. After a fair amount of research and talking with my photographer friends, I decided that I wanted to get a Nikon D7000, which was recently released by Nikon and a Nikon 50mm f/1.8 lens (a “nifty fifty”) to really get the hang of forming my own images.
After deciding what I wanted to buy, I started looking for retailers. I had heard that Adorama and B&H are the two big online stores for serious photographers, so started there. I also looked at Amazon (of course). Then I found out that I could get a $460 printer from Epson (the R1900) with a $400 rebate! Well…apparently everybody wants a D7000 - it was out of stock everywhere! So I checked in on the websites for a couple of days and never found it in stock. You could buy it from Adorama on back order, but in order to get the printer rebate, both the printer and the camera had to be delivered by April, so that worried me (especially after reading that some people wouldn’t get their cameras for months on back order!).
I searched the web for ways to auto-notify you when something came back in stock at Amazon with little luck. I also wanted something that could check the stock at Adorama and B&H so I had all my bases covered. After thinking about it for a little while at work the other day, I thought it would be fun to write my own little app to track the stock of “my” camera on these three websites.
Here is the basic functionality I wanted to build:
- A python (the scripting language I know best) script running every 5 minutes as a cron job that would grab the product page for the Nikon D7000 on Amazon, Adorama, and B&H
- That script would search for certain key words on each page to determine whether it was in stock or not
- If the camera was in stock somewhere, use the Twilio API to send me a text message
It was actually really easy. I signed up for Twilio and got my free $30 of credit, then played around with their examples, accidentally calling myself (instead of texting!). Shortly after that, I texted myself “Hi Greg!”. Then I used the python urllib library to grab the three URLs from the three websites I wanted and simply scanned the page for certain keywords:
- “FREE with Super Saver Shipping” on Amazon
- “currently back ordered” on Adorama
- “temporarily unavailable” on B&H
Finally, I used Twilio to send a text to myself telling me which store had the D7000 in stock as soon as it became available.
It was really a fun experience that took me a whole 30 minutes or so to complete. I posted my script here, so take a look if you’d like and use it as you see fit.
Note: On the day I decided to make this app, my camera became available on Amazon! Even though I didn’t really have any more use for my little app, I decided to make it anyways just to have a chance to play with Twilio and see how it worked.