zoukankan      html  css  js  c++  java
  • Python3.0 我的DailyReport 脚本(四)发送日报

    其实不会用Python,跟风装了Python3.0,看了几天自带的Manual,写个日报的脚本玩玩,不用不要紧,一用感觉还挺好用的

    Host:http://code.google.com/p/haozesdailyreport/

    Code
    #!/usr/bin/env python
    #
    coding=utf-8
    #
    发送日报主程序
    from MailSender import *
    from DBHelper import *
    from ExcelHelper import *
    from datetime import *
    from string import Template
    import logging

    def inputReport():
        today
    =datetime.today()
        weekday
    =today.isoweekday()
        
    if weekday==1:
            d
    =datetime.today()-timedelta(days=3)
        
    elif weekday==7:
            d
    =datetime.today()-timedelta(days=2)
        
    else:
            d
    =datetime.today()-timedelta(days=1)
        dateStr
    =d.strftime("%Y-%m-%d")
        workContent
    =''
        workPecent
    =100
        workHour
    =8
        workPlan
    =''
        workQuestion
    =''
        
        
    while workContent=='':
            workContent
    =input('请输入:'+dateStr+'  工作内容:').strip()
            
        workPecent
    =int(input('请输入 工作完成情况(百分数):').strip())
        workHour
    =int(input('请输入 工作时间(小时):').strip())    
        
        
    while workPlan=='':
            workPlan
    =input('请输入 次日的工作计划:').strip()
            
        
    while workQuestion=='':
            workQuestion
    =input('请输入 遗留问题:').strip()
            
        report
    ={'reportDate':d,'work':workContent,'percent':workPecent,'hourSpent':workHour,'tommorrowPlan':workPlan,'question':workQuestion}
        
    return report

    def createReportHtml(r):
        t 
    = Template(getHmtlTemplate())
        
    return t.substitute(reportDate=r['reportDate'].strftime("%Y-%m-%d"),work=r['work'],percent=r['percent'],hourSpent=r['hourSpent'],tommorrowPlan=r['tommorrowPlan'],question=r['question'])
        
    #邮件的html模版
    def getHmtlTemplate():
        tplstr
    ='''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" >
        <head>
            <title>Untitled Page</title>
            <style type="text/css">
                .style1 {
                    height: 27.0pt;
                     54pt;
                    color: #376091;
                    font-size: 11.0pt;
                    font-weight: 700;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style2 {
                     459pt;
                    color: #376091;
                    font-size: 11.0pt;
                    font-weight: 700;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style3 {
                     164pt;
                    color: #376091;
                    font-size: 11.0pt;
                    font-weight: 700;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style4 {
                     183pt;
                    color: #376091;
                    font-size: 11.0pt;
                    font-weight: 700;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style5 {
                    height: 13.5pt;
                    color: #376091;
                    font-size: 11.0pt;
                    font-weight: 700;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style6 {
                    color: #376091;
                    font-size: 11.0pt;
                    font-weight: 700;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style7 {
                    height: 81.0pt;
                    color: black;
                    font-size: 11.0pt;
                    font-weight: 400;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style8 {
                     206pt;
                    color: black;
                    font-size: 11.0pt;
                    font-weight: 400;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: normal;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style9 {
                    color: black;
                    font-size: 11.0pt;
                    font-weight: 400;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: nowrap;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
                .style10 {
                     164pt;
                    color: black;
                    font-size: 11.0pt;
                    font-weight: 400;
                    font-style: normal;
                    text-decoration: none;
                    font-family: 宋体;
                    text-align: center;
                    vertical-align: middle;
                    white-space: normal;
                    border: .5pt solid windowtext;
                    padding-left: 1px;
                    padding-right: 1px;
                    padding-top: 1px;
                }
            </style>
        </head>
        <body>
        
            <table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
         collapse;860pt" width="1147">
                <colgroup>
                    <col style="54pt" width="72" />
                    <col style="mso-width-source:userset;mso-width-alt:8800;206pt" 
                        width="275" />
                    <col style="mso-width-source:userset;mso-width-alt:4064;95pt" 
                        width="127" />
                    <col style="mso-width-source:userset;mso-width-alt:6752;158pt" 
                        width="211" />
                    <col style="mso-width-source:userset;mso-width-alt:6976;164pt" 
                        width="218" />
                    <col style="mso-width-source:userset;mso-width-alt:7808;183pt" 
                        width="244" />
                </colgroup>
                <tr height="18" style="height:13.5pt">
                    <td class="style1" height="36" rowspan="2" width="72">
                        日期</td>
                    <td class="style2" colspan="3" width="613">
                        工作日报</td>
                    <td class="style3" rowspan="2" width="218">
                        明日计划</td>
                    <td class="style4" rowspan="2" width="244">
                        待解决问题及心得</td>
                </tr>
                <tr height="18" style="height:13.5pt">
                    <td class="style5" height="18">
                        工作内容</td>
                    <td class="style6">
                        完成情况</td>
                    <td class="style6">
                        估计用时(小时)</td>
                </tr>
                <tr height="108" style="mso-height-source:userset;height:81.0pt">
                    <td class="style7" height="108">
                        $reportDate</td>
                    <td class="style8" width="275">
                        $work</td>
                    <td class="style9">
                        $percent%</td>
                    <td class="style9">
                        $hourSpent</td>
                    <td class="style10" width="218">
                        $tommorrowPlan</td>
                    <td class="style9">
                    $question
                         </td>
                </tr>
            </table>
        
        </body>
        </html>
        
    '''
        
    return tplstr

    def sendReport(report):
        
    #添加收件人
        try:
            sender
    =MailSender('mail.iflytek.com','25')
            sender.login(
    'myaccout@iflytek.com','pwd')
        
    except:
            
    print("登陆smtp服务器失败!:", sys.exc_info()[0])
            logging.error(sys.exc_info()[0])
            input()
            exit()    
        sender.to
    ='haozes@gmail.com'
        
    #抄送人,如果是周五的日报,需要抄给部门秘书,其他只抄给项目经理
        if report['reportDate'].isoweekday()==1:
            sender.cc
    ='xxx@iflytek.com'
        
    else:
            sender.cc
    ='xxx@iflytek.com,yyy@iflytek.com'
        mailContent
    =createReportHtml(report)
        
    #print(mailContent)
        
        sender.html
    =mailContent
        sender.setSubject(report[
    'reportDate'].strftime("%Y-%m-%d")+" 工作日报--Haozes")
        
    try:
            sender.send()
            db.updateReport(report)
        
    except:
            
    #db.delReport(report)
            logging.error(sys.exc_info()[0])
                
        info
    ='{0} 日报已发送,收件人:{1},抄送人:{2}'.format(report['reportDate'].strftime("%Y-%m-%d"),sender.to,sender.cc)
        logging.info(info)


            
    LOG_FILENAME 
    = 'log.txt'
    logging.basicConfig(filename
    =LOG_FILENAME,level=logging.INFO,)
        
    if __name__ == "__main__":  
        db
    =DBHelper(r'dailyReport.db3')          
        report
    =inputReport()
        
    while(input('重新输入数据?(Y/N)').strip()=='Y'):
            report
    =inputReport()
        
    #print(report)
        if db.addReport(report):
            
    print('插入数据库成功!')
        
    else:
            
    print('该日日报已发送!')
            input()
            exit()    
        sendReport(report)
        
    print('日报已发送!')
        input(
    'press key to exit')

    最后,我Fuck 日报制度!

  • 相关阅读:
    定时发布测试,没有内容,不要看了,定明天九点发布,看行不
    四十个非常实用的轻量级JavaScript库
    手把手教你用杰奇建小说站
    IIS与Apache共用80端口方法
    jQuery循环滚动展示代码
    分享二十五个不错的下拉菜单导航JS脚本
    以信用卡还信用卡财付通
    codesmith 如何把选中的多个表生成实体
    从零开始学习jQuery 让页面动起来!
    10 个提供免费域名搜索建议服务的网站
  • 原文地址:https://www.cnblogs.com/solo/p/1564198.html
Copyright © 2011-2022 走看看