insert_err_sql=f"insert into dt_err(xydm,`from`,url,title,pub_date,zhaiyao,create_date,state,pageNo,pageIndex) values('{social_code}','{source}','{link}','{title}','{time_format}','{info_page['abstracts']}',now(),1,{num},{pageIndex})"
# selectSql = f"select id,xydm,tycid from ssqy_tyc where state=3 and update_state =1 order by date_time asc limit 1"
selectSql="select id,xydm,tycid from ssqy_tyc where xydm = '91520200214409696J' "
cursor.execute(selectSql)
data=cursor.fetchone()
if(data):
pass
else:
log.info("没有数据了,结束脚本")
break
data_list=list(data)
id=data_list[0]
xydm=data_list[1]
tycid=data_list[2]
# 根据从Redis中拿到的社会信用代码,在数据库中获取对应基本信息
social_code=''
# 判断 如果Redis中已经没有数据,则等待
ifsocial_code=='':
time.sleep(20)
continue
data=baseCore.getInfomation(social_code)
id=data[0]
xydm=data[2]
tycid=data[11]
count=data[17]
log.info(f"{id}---{xydm}----{tycid}----开始处理")
start_time=time.time()
updateBeginSql=f"update ssqy_tyc set update_state=2,date_time=now() where id={id}"
cursor.execute(updateBeginSql)
cnx.commit()
# updateBeginSql = f"update ssqy_tyc set update_state=2,date_time=now() where id={id}"
# cursor.execute(updateBeginSql)
# cnx.commit()
# 开始采集企业动态
retData=beinWork(tycid,xydm)
up_state=retData['up_state']
total=retData['total']
# 信息采集完成后将该企业的采集次数更新
runType='NewsRunCount'
count+=1
baseCore.updateRun(social_code,runType,count)
# up_state = retData['up_state']
total=retData['total']
up_okCount=retData['up_okCount']
up_errorCount=retData['up_errorCount']
up_repetCount=retData['up_repetCount']
ifup_state:
stateNum=1
else:
stateNum=4
# updateEndSql = f"update ssqy_tyc set update_state={stateNum},up_okCount={up_okCount},up_errorCount={up_errorCount},up_repetCount={up_repetCount} ,date_time=now() where id={id}"
# if up_state:
# stateNum = 1
# else:
# stateNum = 4
#
# # 取出数据库中okCount errorCount repetCount 并更新
# selectOrginSql = f"select okCount,errorCount,repetCount,total from ssqy_tyc where id={id}"
# cursor.execute(selectOrginSql)
# count_info = cursor.fetchone()
# okCount = count_info[0]
# errorCount = count_info[1]
# repetCount = count_info[2]
#
# updateEndSql = f"update ssqy_tyc set update_state={stateNum},up_okCount={up_okCount},up_errorCount={up_errorCount},up_repetCount={up_repetCount} ,date_time=now(),okCount={okCount+up_okCount},errorCount={errorCount+up_errorCount},repetCount={repetCount+up_repetCount},total={total} where id={id}"
# cursor.execute(updateEndSql)
# cnx.commit()
# 取出数据库中okCount errorCount repetCount 并更新
selectOrginSql=f"select okCount,errorCount,repetCount,total from ssqy_tyc where id={id}"
cursor.execute(selectOrginSql)
count_info=cursor.fetchone()
okCount=count_info[0]
errorCount=count_info[1]
repetCount=count_info[2]
updateEndSql=f"update ssqy_tyc set update_state={stateNum},up_okCount={up_okCount},up_errorCount={up_errorCount},up_repetCount={up_repetCount} ,date_time=now(),okCount={okCount+up_okCount},errorCount={errorCount+up_errorCount},repetCount={repetCount+up_repetCount},total={total} where id={id}"