求助python操作mysql问题,运行过一段时间,得到的数据类型会变化,不知道怎么回事程序代码如下。
defsave_info_mysql(d,village,price,area,telphone,telphone2):stime=datetime.datetime.f...
def save_info_mysql(d, village, price, area, telphone, telphone2):
stime = datetime.datetime.fromtimestamp(d['CreateTime'])
mycursor = mdb.cursor()
Content = sub_telphone(d)
sql1 = "select count(1) from log where content = '%s'" % (Content)
try:
print(sql1) #这句从始至终都是正常打印的,而且参数传递也都打印过,都是正常的
result=mycursor.execute(sql1)
print(type(result)) #result是个int类型,0或者1,但运行过一段时间程序result的打印结果变成('0',''),程序开始出错,不知道怎么回事,怎么会变成一个例表
print(result)
except Exception as e:
print(e)
print('SQL错误')
if result>0:
print(Content + "数据已经存在")
return
else:
sql = '''INSERT INTO log (wxname,content,stime,village,price,area,telphone6,telphone11,istj) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')''' % (
d['ActualNickName'], Content, str(stime), village, price, area, telphone, telphone2, 0)
print(sql)
mycursor.execute(sql)
mdb.commit()
#message = d['ActualNickName'] + " 说:" + Content + " 时间 " + str(stime)
group = itchat.get_chatrooms(update=True)
# =====================================================
for g in range(len(group)):
if group[g]['NickName'] in groups:
itchat.send(Content, group[g]['UserName'])
print(Content + '写入数据')
#time.sleep(2) 展开
stime = datetime.datetime.fromtimestamp(d['CreateTime'])
mycursor = mdb.cursor()
Content = sub_telphone(d)
sql1 = "select count(1) from log where content = '%s'" % (Content)
try:
print(sql1) #这句从始至终都是正常打印的,而且参数传递也都打印过,都是正常的
result=mycursor.execute(sql1)
print(type(result)) #result是个int类型,0或者1,但运行过一段时间程序result的打印结果变成('0',''),程序开始出错,不知道怎么回事,怎么会变成一个例表
print(result)
except Exception as e:
print(e)
print('SQL错误')
if result>0:
print(Content + "数据已经存在")
return
else:
sql = '''INSERT INTO log (wxname,content,stime,village,price,area,telphone6,telphone11,istj) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')''' % (
d['ActualNickName'], Content, str(stime), village, price, area, telphone, telphone2, 0)
print(sql)
mycursor.execute(sql)
mdb.commit()
#message = d['ActualNickName'] + " 说:" + Content + " 时间 " + str(stime)
group = itchat.get_chatrooms(update=True)
# =====================================================
for g in range(len(group)):
if group[g]['NickName'] in groups:
itchat.send(Content, group[g]['UserName'])
print(Content + '写入数据')
#time.sleep(2) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询