Nexus 4 on stock notification

So today the Nexus 4 launched and the F5 spam rained upon Google's servers. Due to several issues with Google's services, I wasn't able to snatch one of these great devices, so I'm stuck here wondering when they will have more available for purchase. Maybe if I had a computer.. that could somehow check for me, whenever an Nexus is available for sale.. hmm.

Nexus Notification Script

This script searches for the specific button in the Google Play store that appears
when the phone is in stock and you are able to buy it. It will send you an email
as a notification.

written by: Marco A Morales

import smtplib
import requests
import datetime

PASSWORD = 'xxxxxxxxxxxxx'

test_url = ''
test_search_pattern = 'google'

# This URL is for the 16GB version.
url = ''
search_pattern = 'buy-hardware-form'

def check_nexus(url, search_pattern):
    r = requests.get(url)
    if r.text.find(search_pattern) != -1:
        print 'NEXUS FOUND!'
        print 'Nothing found: ' + str(

def send_mail(smtp_server, smtp_port, sender, password):
    subject = 'NEXUS FOUND'
    body = 'Your script has found a Nexus 4 Device in the Google Play Store.'

    # I send an email from me to me, so I use the same email for sender and recipient
    headers = ["From: " + sender,
           "Subject: " + subject,
           "To: " + sender,
           "MIME-Version: 1.0",
           "Content-Type: text/html"]
    headers = "\r\n".join(headers)
    session = smtplib.SMTP(smtp_server, smtp_port)

    session.login(sender, password)

    session.sendmail(sender, sender, headers + "\r\n\r\n" + body)

def main():
    check_nexus(url, search_pattern)

if __name__ == '__main__':

So here it is, a python script I made that will tell you whenever a phone is up for sale. It works by searching for the id of the "Add to cart" button. I'm running this script every minute with cron:

* * * * * /usr/bin/python2.7 ~/ >> ~/nexus-log.log 2>&1

I hope this will help someone grab a Nexus 4, I'll report back if this script helped me in any way. Happy hunting.

comments powered by Disqus