您的位置:首页 > 编程语言 > Python开发

收集部门人员一次二次推荐python脚本--参考

2014-10-15 10:16 211 查看
#!/usr/bin/env python
#encoding:utf-8
import MySQLdb
tell_file='/home/test/liyiliang/study/tell.info'
f = file(tell_file)
account_list = f.readlines()
f.close()
for n in account_list:
h=n.strip().split()
name = h[0]
phone = h[1]
try:
conn = MySQLdb.connect(host='x.x.x.x',user='xxxx',passwd='xxxxxxx',port=xxxxx,charset='utf8')
cur = conn.cursor()
cur.execute('select promotioncode from cinf_db.cinf_promotioncode where mp = %s',phone)
mycode = cur.fetchall()
numTwo=0
for code in mycode:
cur.execute('select mp from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode = %s',code)
op = cur.fetchall()
cur.execute('select count(*) from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode= %s ',code)
mynum = cur.fetchall()
for opnum in op:
cur.execute('select promotioncode from cinf_db.cinf_promotioncode  where mp = %s',opnum)
othercode = cur.fetchall()
for oc in othercode:
cur.execute('select count(*) from cinf_db.cinf_promotioncode_reward_history where reward_type=1 and promotioncode = %s',oc)
everone = cur.fetchall()
for a in everone:
b=int(a[0])
numTwo += b
for numOne in mynum:
print '%s' %name,
print '%s' %phone,
print '%s' %numOne,
print '%s' %numTwo

cur.close()
conn.close()
except MySQLdb.Error,e:
print "MySQLdb Error",e
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python