Skip to content

Instantly share code, notes, and snippets.

@dreampuf
Created December 12, 2012 06:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreampuf/4265597 to your computer and use it in GitHub Desktop.
Save dreampuf/4265597 to your computer and use it in GitHub Desktop.
Interval tool for check buyvm.net activate Instance send email to inform your by email
#!/usr/bin/env python
#vi: encoding=utf-8
""" Interval tool for check buyvm.net activate Instance send email to inform your by email
http://huangx.in
"""
import time
import json
import urllib2
import smtplib
from contextlib import closing
from email.MIMEText import MIMEText
TARGET = 'http://www.doesbuyvmhavestock.com/automation.json'
EMAIL_USERNAME = "your mandrillapp account"
EMAIL_PASSWORD = "your mandrillapp key"
EMAIL_TARGET = "your email address"
WANTER = ("SJ OpenVZ-128MB",
"SJ KVM-128MB",
"NY OpenVZ-128MB",
"NY KVM-128MB")
while True:
with closing(urllib2.urlopen(TARGET)) as f:
d = json.loads(f.read())
want = [i for i in d if i["name"] in WANTER and i["qty"] > 0]
if want:
content = str(want)
email_server = smtplib.SMTP("smtp.mandrillapp.com", port=587)
email_server.login(EMAIL_USERNAME, EMAIL_PASSWORD)
msg = MIMEText(content, "html", "utf-8")
msg["From"] = "notify@BIGBONE.com"
msg["Subject"] = "BUYVM come!"
msg["To"] = EMAIL_TARGET
email_server.sendmail("notify@BIGBONE.com", EMAIL_TARGET, msg.as_string())
time.sleep(300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment