Skip to content

Instantly share code, notes, and snippets.

@yszheda
Created March 25, 2016 11:31
Show Gist options
  • Save yszheda/9bf9fbdc787753f4760e to your computer and use it in GitHub Desktop.
Save yszheda/9bf9fbdc787753f4760e to your computer and use it in GitHub Desktop.
auto generate your daily work report by scanning your commits in the git repo, and send the mail to your boss.
#!/usr/bin/env python
# coding:utf-8
import sys
import git
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import time
SENDER = ""
RECEIVERS = "boss1 boss2".split(' ')
REPO_PATH = "YourRepo"
AUTHOR_NAME = u"YourGitName"
NAME = u"YourName"
def gen_report_content():
content = u"今日工作:\n"
repo = git.Git(REPO_PATH)
content = content + repo.log(pretty="%s", author=AUTHOR_NAME, since="0am")
# print content
return content
def gen_report_subject():
return u"%s 日报-%s" % (NAME, time.strftime("%Y-%m-%d"))
def send_mail():
message = MIMEMultipart('alternative')
message['From'] = SENDER
message['Subject'] = gen_report_subject()
content = gen_report_content()
content = MIMEText(content, "plain", "utf-8")
message.attach(content)
for i, receiver in enumerate(RECEIVERS):
message['To'] = receiver
print message.as_string()
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(SENDER, receiver, message.as_string())
print "Successfully sent email to ", receiver
smtpObj.quit()
except smtplib.SMTPException:
print "Error: unable to send email to ", receiver
def main(argv):
send_mail()
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment