add workflow 天润Smart-ccc客户数据,dev
This commit is contained in:
parent
2fcc452226
commit
ba47d55c40
|
@ -25,7 +25,6 @@ upt_sql = "update p61_output.ccc_scrm_cust_label_info set sync_ind=%s, etl_proc_
|
||||||
ist_sql = "INSERT INTO p61_output.scrm_leads_external_id_mapping (leads_id, external_type, external_id, etl_proc_dt, etl_tx_dt) VALUES (%s, %s, %s,current_timestamp(0), current_date) on CONFLICT (leads_id, external_type) DO NOTHING;"
|
ist_sql = "INSERT INTO p61_output.scrm_leads_external_id_mapping (leads_id, external_type, external_id, etl_proc_dt, etl_tx_dt) VALUES (%s, %s, %s,current_timestamp(0), current_date) on CONFLICT (leads_id, external_type) DO NOTHING;"
|
||||||
# ist_sql = "delete from p61_output.scrm_leads_external_id_mapping where leads_id=%s and external_type = %s ; INSERT INTO p61_output.scrm_leads_external_id_mapping (leads_id, external_type, external_id, etl_proc_dt, etl_tx_dt) VALUES (%s, %s, %s,current_timestamp(0), current_date);"
|
# ist_sql = "delete from p61_output.scrm_leads_external_id_mapping where leads_id=%s and external_type = %s ; INSERT INTO p61_output.scrm_leads_external_id_mapping (leads_id, external_type, external_id, etl_proc_dt, etl_tx_dt) VALUES (%s, %s, %s,current_timestamp(0), current_date);"
|
||||||
|
|
||||||
|
|
||||||
database="daas_mpp"
|
database="daas_mpp"
|
||||||
user="dbuser_mpp"
|
user="dbuser_mpp"
|
||||||
password="qwF0GX8"
|
password="qwF0GX8"
|
||||||
|
@ -83,16 +82,15 @@ def add_leads_id(sql, type, leads_id, extern_id):
|
||||||
print(f'添加线索id异常,接口返回信息:{e}')
|
print(f'添加线索id异常,接口返回信息:{e}')
|
||||||
|
|
||||||
def request_custom_id(id):
|
def request_custom_id(id):
|
||||||
print(f'开始请求线索id:{id}')
|
|
||||||
header={}
|
header={}
|
||||||
url='https://api.huiju.cool/v2/customerService/findCustomerByIdentity'
|
url='https://api.huiju.cool/v2/customerService/findCustomerByIdentity'
|
||||||
body={'access_token':auth['access_token'],'identityType':identityType,'identityValue':id}
|
body={'access_token':auth['access_token'],'identityType':identityType,'identityValue':id}
|
||||||
|
print(f'body: {body}')
|
||||||
dataReqL=requests.get(url,headers=header,params=body)
|
dataReqL=requests.get(url,headers=header,params=body)
|
||||||
resL=json.loads(dataReqL.text)
|
resL=json.loads(dataReqL.text)
|
||||||
return resL
|
return resL
|
||||||
|
|
||||||
def request_update_tags(idStr, tagId ):
|
def request_update_tags(idStr, tagId ):
|
||||||
print(f'开始请求更新线索标签{idStr}|{tagId}')
|
|
||||||
header={}
|
header={}
|
||||||
access_token = auth['access_token']
|
access_token = auth['access_token']
|
||||||
url=f'https://api.huiju.cool/v2/customerTags/bulkAdd?access_token={access_token}'
|
url=f'https://api.huiju.cool/v2/customerTags/bulkAdd?access_token={access_token}'
|
||||||
|
@ -113,43 +111,47 @@ if __name__ == "__main__":
|
||||||
records = get_data_from_db( sel_sql)
|
records = get_data_from_db( sel_sql)
|
||||||
if len(records) > 0:
|
if len(records) > 0:
|
||||||
print(f'此处需处理{len(records)}条标签信息')
|
print(f'此处需处理{len(records)}条标签信息')
|
||||||
|
i = 0
|
||||||
for data in records:
|
for data in records:
|
||||||
|
i = i+1
|
||||||
custId = data[0]
|
custId = data[0]
|
||||||
id = data[1]
|
id = data[1]
|
||||||
idStr = data[2]
|
idStr = data[2]
|
||||||
tagId = data[5]
|
tagId = data[5]
|
||||||
print(f'开始处理客户({id}:{tagId})标签信息')
|
print(f'{i}. 开始处理客户({id}:{tagId})标签信息')
|
||||||
try:
|
try:
|
||||||
f = False
|
f = False
|
||||||
s = '2'
|
s = '2'
|
||||||
if not idStr:
|
if not idStr:
|
||||||
|
print(f'{i}. 开始请求线索id:{id}')
|
||||||
resL = request_custom_id(id)
|
resL = request_custom_id(id)
|
||||||
if 'error' in resL and resL['error']['code'] == 400010:
|
if 'error' in resL and resL['error']['code'] == 400010:
|
||||||
get_token(auth_url)
|
get_token(auth_url)
|
||||||
resL = request_custom_id(id)
|
resL = request_custom_id(id)
|
||||||
if 'error' in resL:
|
if 'error' in resL:
|
||||||
print(f'获取客户线索id异常,接口返回信息:{resL}')
|
print(f'{i}. 异常:获取客户线索id异常,接口返回信息:{resL}')
|
||||||
continue
|
continue
|
||||||
idStr = resL['idStr']
|
idStr = resL['idStr']
|
||||||
if idStr == '':
|
if idStr == '':
|
||||||
print(f'获取客户线索id为空,接口返回信息:{resL}')
|
print(f'{i}. 异常:获取客户线索id为空,接口返回信息:{resL}')
|
||||||
continue
|
continue
|
||||||
f=True
|
f=True
|
||||||
if f:
|
if f:
|
||||||
add_leads_id(ist_sql,identityType, idStr, id)
|
add_leads_id(ist_sql,identityType, idStr, id)
|
||||||
if tagId is None:
|
if tagId is None:
|
||||||
print(f'标签id为空,无法更新标签{tagId}')
|
print(f'{i}. 异常:标签id为空,无法更新标签{tagId}')
|
||||||
continue
|
continue
|
||||||
|
print(f'{i}. 开始请求更新线索标签{idStr}|{tagId}')
|
||||||
resU = request_update_tags(idStr,tagId)
|
resU = request_update_tags(idStr,tagId)
|
||||||
if 'error' in resU and resU['error']['code'] == 400010:
|
if 'error' in resU and resU['error']['code'] == 400010:
|
||||||
get_token(auth_url)
|
get_token(auth_url)
|
||||||
resU = request_update_tags(idStr,tagId)
|
resU = request_update_tags(idStr,tagId)
|
||||||
if 'error' in resU:
|
if 'error' in resU:
|
||||||
print(f'获取客户线索id异常,接口返回信息:{resU}')
|
print(f'{i} 异常:获取客户线索id失败,接口返回信息:{resU}')
|
||||||
continue
|
continue
|
||||||
update_db_flag( upt_sql,s,custId,tagId)
|
update_db_flag( upt_sql,s,custId,tagId)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'处理客户({id}:{tagId})标签信息,异常信息:{e}')
|
print(f'{i} 异常:处理客户({id}:{tagId})标签信息,异常信息:{e}')
|
||||||
else:
|
else:
|
||||||
print(f'记录数为0,此处无需处理标签信息')
|
print(f'记录数为0,此处无需处理标签信息')
|
||||||
print(f'{formatted2_previous_hour(0)}更新标签信息结束')
|
print(f'{formatted2_previous_hour(0)}更新标签信息结束')
|
||||||
|
|
Loading…
Reference in New Issue