Created
November 14, 2012 21:38
-
-
Save spacetime/4075011 to your computer and use it in GitHub Desktop.
Nexus 4 availability email script (using sendmail)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from urllib import urlopen | |
import smtplib | |
import logging | |
import os | |
sender = '[email protected]' | |
recipients = ['[email protected]' | |
'[email protected]', | |
'[email protected]', | |
#add more here | |
] | |
subject = 'Nexus 4 back in stock!?' | |
body = """ | |
Check Google Play US Store! | |
You are receiving this email since you signed up for an alert from my experimental script. | |
If this message reaches on time, drop me a comment on blog.rishab.in and make my day! | |
If it doesn't.. errr.. oops. I tried. ^_^ | |
Rishab Arora | |
(spacetime) | |
[email protected] | |
""" | |
contents = urlopen("https://play.google.com/store/devices/details?id=nexus_4_16gb").read() | |
if contents.find("buy-hardware-button") != -1: #Page doesn't say Sold Out anymore! | |
message = "\r\n".join(["From: " + sender, | |
"Subject: " + subject, | |
"To: [email protected]", | |
"Bcc: " + ", ".join(recipients), | |
"MIME-Version: 1.0", | |
"Content-Type: text/plain", | |
body]) | |
try: | |
SENDMAIL = "/usr/sbin/sendmail" # sendmail location | |
#more likely to end up in spam for me | |
p = os.popen("%s -t -i" % SENDMAIL, "w") | |
p.write(message) | |
status = p.close() | |
if status: | |
print "Sendmail exit status", status | |
except Exception: | |
print logging.exception('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment