37,720
社区成员
发帖
与我相关
我的任务
分享
# Yaml格式配置文件 Config.yaml
host: dbhost
user: dbuser
password: "dbpwd"
database: thetestdb
sqlstring_summaryDaily:
select [date], charge, monthsummary
from ds_collect
where code=$code
order by [date] desc
threshold_values:
"099023":
name: name of the custmoer
daily: 600.00
monthSummary: 2500.00
"000000":
name: 2nd customer's name
daily: 800.00
monthSummary: 3000.00
# 以下为Python脚本代码 #############################
#!python
# -*- coding:GBK -*-
import yaml
import pymssql
import string
config = yaml.load(file('Config.yaml', 'r'))
conn = pymssql.connect(host=config['host'],
user=config['user'],
password=config['password'],
database=config['database'])
conn.row_factory=str
curr = conn.cursor()
pageTmpl = "$name .. <table><tr><td>Date</td><td>Daily</td><td>MnSummary</td></tr>$trs</table>" # 此处具体内容简化
trFmt = "<tr><td>%s</td><td>%s</td><td>%s</td></tr>"
for code in config['threshold_values']:
tvalues = config['threshold_values'][code]
dgate , mgate = float(tvalues['daily']) , float(tvalues['monthSummary'])
trs , atrs = [] , ""
curr.execute(string.Template(config['sqlstring_summaryDaily']).safe_substitute(dict(code=code)))
for (date,dsum, msum,) in curr.fetchall():
trs.append(trFmt % (
date.strftime("%d, %b"),
dsum,
msum))
open("%s.html" % code,"w").writelines(pageTmpl.safe_substitute(dict(
name = tvalues['name'], trs = "\n".join(trs),
)))
curr.close()
conn.close()
#!python
# -*- coding:utf-8 -*-
import yaml
import pymssql
import string
config = yaml.load(file('testcfg.yaml', 'r'))
conn = pymssql.connect(host=config['host'],
user=config['user'],
password=config['password'],
database=config['database'])
conn.row_factory=str
curr = conn.cursor()
pageTmpl = "$name .. <table><tr><td>Date</td><td>Daily</td><td>MnSummary</td></tr>$trs</table>"
trFmt = "<tr><td>%s</td><td>%s</td><td>%s</td></tr>"
for code in config['threshold_values']:
tvalues = config['threshold_values'][code]
dgate , mgate = float(tvalues['daily']) , float(tvalues['monthSummary'])
trs , atrs = [] , ""
curr.execute(string.Template(config['sqlstring_summaryDaily']).safe_substitute(dict(code=code)))
for (date,dsum, msum,) in curr.fetchall():
trs.append(trFmt % (
date.strftime("%d, %b"),
dsum,
msum))
open("%s.html" % code,"w").writelines(pageTmpl.safe_substitute(dict(
name = tvalues['name'], trs = "\n".join(trs),
)))
curr.close()
conn.close()
host: 192.168.10.15
user: sa
password: "780702"
database: gabill
sqlstring_summaryDaily:
select [date], charge, monthsummary
from ds_collect
where code=$code
order by [date] desc
threshold_values:
"099023":
name: 重要客户
daily: 600.00
monthSummary: 2500.00
"000000":
name: 测试客户
daily: 800.00
monthSummary: 3000.00