I’m currently a bit obsessed with the LG Nexus 4. The price tag, specs and design seem to be a fairly amazing combination. The trouble is, however, it’s been available in Canada for a grand total of ten minutes from what I can tell.
To combat the problem, a friend reminded me on Twitter that I am software developer, and that I can automate things. I set to work, and arrived at the following solution:
- A command line script that checks the Nexus 4’s web page to check if its in stock.
- If it is, this uses a Ruby script called “t” to send me a direct message
- Direct messages are desirable for me as they reliably get to my phone
Command Line to Check Google Play to See if the Nexus 4 Is In Stock
test $(curl -s https://play.google.com/store/devices/details?id=nexus_4_16gb \ | tr -d '\n' | grep -vi "sold out" |wc -l) -eq 1 && \ t dm @yourtwitter "check google play"
The one thing I’m worried about; the machine I’m running this on sits in the US, and I’m concerned that there might be stock for Canadian clients but not US, and vice versa, so I’m running it on my MacBook too for good luck.
To get this to work, your crontab needs to set up a decent Ruby environment; mine looks like this (though I’m certain that this could be improved):
kyleh@vm:~$ crontab -l rvm_bin_path=/home/kyleh/.rvm/bin GEM_HOME=/home/kyleh/.rvm/gems/ruby-1.9.3-p194 IRBRC=/home/kyleh/.rvm/rubies/ruby-1.9.3-p194/.irbrc MY_RUBY_HOME=/home/kyleh/.rvm/rubies/ruby-1.9.3-p194 PATH=/home/kyleh/.rvm/gems/ruby-1.9.3-p194/bin PATH=$PATH:/home/kyleh/.rvm/gems/ruby-1.9.3-p194@global/bin PATH=$PATH:/home/kyleh/.rvm/rubies/ruby-1.9.3-p194/bin:/home/kyleh/.rvm/bin PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin PATH=$PATH:/bin RUBY_VERSION=ruby-1.9.3-p194 GEM_PATH=/home/kyleh/.rvm/gems/ruby-1.9.3-p194 GEM_PATH=$GEM_PATH:/home/kyleh/.rvm/gems/ruby-1.9.3-p194@global * * * * * test $(curl -s https://play.google.com/store/devices/details?id=nexus_4_16gb \ | tr -d '\n' | grep -vi "sold out" |wc -l) -eq 1 && \ t dm @yourtwitter "check google play"
Installing t is simple, just gem install t. The first time you run t, just do t authorize and it will walk you through authorizing t to talk to Twitter for you.