Esempio n. 1
0
def getConnOne(dbConf, sec):
    host = dbConf.get(sec,"host")
    port = dbConf.getint(sec,"port")
    user = dbConf.get(sec,"user")
    password = dbConf.get(sec,"password")
    database = dbConf.get(sec,"database")
    conn = commonutil.getConn(host, port, user, password, database)
    if conn is None:
        time.sleep(5)
        conn = commonutil.getConn(host, port, user, password, database)
    if conn is None:
        commonutil.fatal("fail to get connection : sec=[{0}]".format(sec))
    return conn
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)