cz-sjm 发表于 2017-4-30 11:25:43

python的强悍(二)

  按照需求,从新改写了一下,而这些只是几分钟时间而已。

import cx_Oracle
from Template import *
def parse():
'''generate the content html'''
sql = '''select t.bz_code code, t.bz_title title, t.bz_content content
from bz_czzs t
order by t.bz_code'''
connection = cx_Oracle.connect( 'etasadmin/etasadmin@zhongju' )
cursor = connection.cursor()
cursor.execute(sql)
item=cursor.fetchone()
i=1;
print 'begin'
while item:
i+=1
print 'parsing ',i,' item....'
writeContent(item,item,str(item))
item=cursor.fetchone()
def writeContent(code,title,content):
filedir='D:\m\content\'
params = {'code':code,'title':title,'content':content}
t = Template('D:\workspace\style\test\template.xt',params)
s = t.parse()
out = open(filedir+code+".html",'w')
out.write(s)
out.flush()
out.close()
if __name__=='__main__':
print 'parse..................'   
parse()
print 'end'
页: [1]
查看完整版本: python的强悍(二)