提交 a4e06d07 作者: 薛凌堃

获取天眼查id脚本维护

上级 07886a4e
...@@ -22,9 +22,11 @@ headers = { ...@@ -22,9 +22,11 @@ headers = {
'version':'TYC-Web', 'version':'TYC-Web',
'Content-Type':'application/json;charset=UTF-8' 'Content-Type':'application/json;charset=UTF-8'
} }
cnx = pymysql.connect(host='114.116.44.11', user='caiji', password='f7s0&7qqtK', db='dbScore', charset='utf8mb4') # cnx = pymysql.connect(host='114.116.44.11', user='caiji', password='f7s0&7qqtK', db='dbScore', charset='utf8mb4')
cursor= cnx.cursor() # cursor= cnx.cursor()
cnx_ = baseCore.cnx
cursor_ = BaseCore.cursor
taskType = '天眼查企业id/天眼查'
#根据信用代码获取天眼查id 企业名字等信息 #根据信用代码获取天眼查id 企业名字等信息
def getTycIdByXYDM(xydm): def getTycIdByXYDM(xydm):
retData={'state':False,'tycData':None,'reput':True} retData={'state':False,'tycData':None,'reput':True}
...@@ -59,39 +61,51 @@ def getTycIdByXYDM(xydm): ...@@ -59,39 +61,51 @@ def getTycIdByXYDM(xydm):
# 更新天眼查企业基本信息 # 更新天眼查企业基本信息
def updateTycInfo(id,retData): def updateTycInfo():
state= retData['state'] while True:
if state : # 根据从Redis中拿到的社会信用代码,在数据库中获取对应基本信息
data = retData['tycData'] social_code = baseCore.redicPullData('NewsEnterprise:gnqy_socialCode')
updateSql=f"update tyc_com_info set state=3,update_date=now(),tycid='{data['id']}', type='{data['type']}',comName='{data['comName']}',name='{data['name']}'" \ # social_code = '912301001275921118'
f",alias='{data['alias']}',logo='{data['logo']}',claimLevel='{data['claimLevel']}',regStatus='{data['regStatus']}' where id={id}" # 判断 如果Redis中已经没有数据,则等待
else: if social_code == None:
updateSql = f"update tyc_com_info set state=4,update_date=now() where id={id}" time.sleep(20)
cursor.execute(updateSql) continue
cnx.commit() start = time.time()
#采集工作 data = baseCore.getInfomation(social_code)
def beginWork(): if len(data) != 0:
while True :
start =time.time()
selectSql="select id,xydm from tyc_com_info where state=1 order by update_date asc ,id asc limit 1"
cursor.execute(selectSql)
data = cursor.fetchone()
if data:
pass pass
else: else:
log.info("没有数据了,结束脚本") # 数据重新塞入redis
break baseCore.rePutIntoR('NewsEnterprise:gnqy_socialCode', social_code)
data_list = list(data) continue
id = data_list[0]
xydm = data_list[1] xydm = data[2]
tycid = data[11]
if tycid == None or tycid == '':
try:
retData = getTycIdByXYDM(xydm) retData = getTycIdByXYDM(xydm)
updateTycInfo(id,retData) if retData['tycData'] and retData['reput']:
log.info(f"{id}---{xydm}----处理完成,耗时:{baseCore.getTimeCost(start,time.time())}") tycid = retData['id']
cursor.close() # todo:写入数据库
cnx.close() updateSql = f"update EnterpriseInfo set TYCID = '{tycid}' where SocialCode = '{xydm}'"
# 释放资源 cursor_.execute(updateSql)
baseCore.close() cnx_.commit()
elif not retData['tycData'] and retData['reput']:
state = 0
takeTime = baseCore.getTimeCost(start, time.time())
baseCore.recordLog(social_code, taskType, state, takeTime, '', '获取天眼查id失败')
log.info(f'======={social_code}====重新放入redis====')
baseCore.rePutIntoR('NewsEnterprise:gnqy_socialCode', social_code)
continue
elif not retData['reput'] and not retData['tycData']:
continue
except:
state = 0
takeTime = baseCore.getTimeCost(start, time.time())
baseCore.recordLog(social_code, taskType, state, takeTime, '', '获取天眼查id失败')
baseCore.rePutIntoR('NewsEnterprise:gnqy_socialCode', social_code)
continue
if __name__ == '__main__': if __name__ == '__main__':
beginWork() updateTycInfo()
\ No newline at end of file \ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论