Esempio n. 1
0
def makeTrs(templateFileName, dateFileName):
    content = ""
    template = reportutil.readFile(templateFileName)
    dateFile = open(dateFileName, "r")
    for line in dateFile:
        fields = line.strip("\n").split("\x01")
        #计算某些列
	fields[5] = (int)(fields[4]) - (int)(fields[3])
        fields[6] = (int)(fields[2]) - (int)(fields[5])
        if fields[3] == "0":
            fields[7] = "-"
        else:
	    fields[7] = "{0:10.2f}".format((float)(fields[6])*100/(int)(fields[3]))
        if fields[9] == "0":
            fields[10] = "-"
        else:
	    fields[10] = "{0:10.2f}".format((float)(fields[8])/(int)(fields[9]))
	content = content + template.format(fields)
    dateFile.close()
    return content 
Esempio n. 2
0
    if d != "" :
        os.chdir(d)
    #解析参数
    options = getOptions()
    targetDate = getTargetDate(options.targetDate)
    #准备工作
    outputPath = os.path.abspath("./output")+"/"+targetDate.strftime("%Y-%m-%d")
    commonutil.runCmd("mkdir -p", outputPath)
    mailConf = reportutil.getConf('mail.conf')
    dbConf = reportutil.getConf('db.conf')
    conns = reportutil.getConns(dbConf)
    targetDateStart = targetDate.strftime("%Y-%m-%d 00:00:00")
    targetDateEnd = (targetDate+timedelta(days=1)).strftime("%Y-%m-%d 00:00:00")
    targetDateEarly = (targetDate+timedelta(days=-7)).strftime("%Y-%m-%d 00:00:00")
    outputFile = outputPath+"/data"
    reportutil.truncateFile(outputFile)
    #拉取数据
    vars = {'VAR_START':targetDateStart, 'VAR_END':targetDateEnd, 'VAR_EARLY':targetDateEarly}
    isSuccess = dumpmysql.dump(conns['mall'], 'report.sql', outputFile, vars, True)
    if not isSuccess:
        commonutil.fatal("[{0}] failed".format(targetDateStart))
        sys.exit(1)
    commonutil.info("[{0}] done".format(targetDateStart))
    #生成报表
    html = reportutil.readFile('template.head')
    html = html + makeTrs('template.mid', outputFile)
    html = html + reportutil.readFile('template.tail')
    #发送邮件
    sendMail(targetDate, html, mailConf)