Nexus 4 availability email script (using sendmail)
This file contains 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 = 'youremail@here.com' | |
recipients = ['abc@gmail.com' | |
'abc@def.com', | |
'asd@asd.com', | |
#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) | |
ra.rishab@gmail.com | |
""" | |
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: ra.rishab@gmail.com", | |
"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