Skip to content

Instantly share code, notes, and snippets.

@diggzhang
Created June 16, 2016 09:36
Show Gist options
  • Save diggzhang/7a107d63882db4f67e1998f8a88e0b37 to your computer and use it in GitHub Desktop.
Save diggzhang/7a107d63882db4f67e1998f8a88e0b37 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import os, urllib2, sys
import datetime
import random
import subprocess
import smtplib
from email.mime.text import MIMEText
# mail configure
mailto_list=["[email protected]","[email protected]"]
mail_host="smtp.126.com"
mail_user="XX"
mail_pass="XX"
mail_postfix="126.com"
def randomMsg():
msgList = [
"临时加班,晚点回家,下班给你打电话.",
"公司临时有事,晚点回家,下班给你打电话.",
"= = 代码出了bug,加班ing,晚点回家,下班给你打电话",
"T_T 加班ing,下班给你打电话",
]
rndNum = random.randint(0,3)
return msgList[rndNum]
def sendMail(toList, subject, content):
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = me
msg['To'] = ";".join(toList)
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, toList, msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False
# 检查进程中是否存在工作时才出现的进程
def checkProcess():
output = subprocess.check_output('ps')
if 'zsh' not in output:
print("没有工作,程序退出")
sys.exit()
else:
if sendMail(mailto_list, "今天晚点回家", randomMsg()):
print("邮件发送成功")
sys.exit()
else:
print("code done")
def isWeekend(thisDay):
if thisDay == 5 or thisDay == 6:
print ("周六日不上班.")
sys.exit()
elif thisDay == 3:
sendMail(mailto_list, "周四团建", "周四照例团建,晚点回去.")
sys.exit()
else:
checkProcess()
# check this day is sunday?
thisDay = datetime.datetime.today().weekday()
isWeekend(thisDay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment