1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
   | from datetime import datetime import time from PIL import ImageGrab import os import threading
 
  def send_mail(mail_title='', mail_content='', pic_name=''):     from email.mime.text import MIMEText     from email.header import Header     from smtplib import SMTP_SSL
      from email.mime.application import MIMEApplication     from email.mime.multipart import MIMEMultipart
      sender = 'xx@qq.com'     receiver = 'xx@qq.com'     pwd = 'xxxxxxxxxxxx'                
      smtp = SMTP_SSL('smtp.qq.com')           smtp.login(sender, pwd)
      msg = MIMEMultipart()     msg["Subject"] = Header(mail_title, 'utf-8')     msg["from"] = sender     msg["to"] = receiver
      puretext = MIMEText('content: '+mail_content)     msg.attach(puretext)
      jpgpart = MIMEApplication(open(pic_name, 'rb').read())     jpgpart.add_header('Content-Disposition', 'attachment', filename=pic_name)     msg.attach(jpgpart)          smtp.sendmail(sender, receiver, msg.as_string())     smtp.quit()         
  def func():     t = time.localtime(time.time())     min, hour, wkday = t.tm_min, t.tm_hour, t.tm_wday          if min in [0, 15, 30, 45]:         time_now = time.strftime('%Y%m%d-%H%M%S')         pic = ImageGrab.grab()         pic_name = time_now+'.jpg'         pic.save(pic_name)
          title = 'mgso4 test monitor ' + time_now         send_mail(title, title, pic_name)              
      global timer     timer = threading.Timer(60, func, [])     timer.start()
 
  if __name__ == "__main__":     timer = threading.Timer(1, func, [])     timer.start()
   |