add workflow 天润Smart-ccc客户数据,dev
This commit is contained in:
parent
2d2494b6f6
commit
1a901f1faf
|
@ -75,10 +75,10 @@ def build_query_string(params):
|
|||
|
||||
|
||||
#计算签名,get请求
|
||||
def request_list_signature_get():
|
||||
def request_list_signature_get(offset,pageSize):
|
||||
print('开始请求数据...')
|
||||
url='https://api-bj.clink.cn/crm/list_customers'
|
||||
param={'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','Timestamp':current_time_utc,'Expires':86400,'updateStartTime':previous_hour_timestamp(1),'updateEndTime':previous_hour_timestamp(0),'limit':100}
|
||||
param={'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','Timestamp':current_time_utc,'Expires':86400,'updateStartTime':previous_hour_timestamp(48),'updateEndTime':previous_hour_timestamp(0),'offset':offset,'limit':pageSize}
|
||||
# param={'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','Timestamp':current_time_utc,'Expires':86400,'updateStartTime':1704038400,'updateEndTime':previous_hour_timestamp(0)}
|
||||
print(f'param: {param}')
|
||||
url_path = build_query_string(param)
|
||||
|
@ -102,6 +102,7 @@ def request_list_signature_get():
|
|||
resText = dataReqL.text
|
||||
i = i + 1
|
||||
resL=json.loads(resText)
|
||||
print(dataReqL)
|
||||
return resL
|
||||
|
||||
def request_detail_signature_post(customerId):
|
||||
|
@ -185,36 +186,51 @@ def load_detail_exp_to_db(id):
|
|||
|
||||
if __name__ == "__main__":
|
||||
print(f'{formatted2_previous_hour(0)}开始请求客户资料信息')
|
||||
resL = request_list_signature_get()
|
||||
offset = 0
|
||||
pageSize = 100
|
||||
resL = request_list_signature_get(offset,pageSize)
|
||||
print(resL)
|
||||
if 'error' in resL:
|
||||
error = resL['error']
|
||||
print(f'请求客户资料列表失败,失败原因:{error}')
|
||||
else:
|
||||
dataList = resL['customers']
|
||||
load_data_to_db(dataList)
|
||||
list = resL['customers']
|
||||
page = resL['pageNumber']
|
||||
total = resL['totalCount']
|
||||
print(f'此次请求数据总数为:{total},需要请求{int(total/pageSize) + 1}次')
|
||||
i = 1
|
||||
while page * pageSize < total:
|
||||
i = i+1
|
||||
offset = page * pageSize
|
||||
resL = request_data_signature_post(offset, pageSize)
|
||||
list = list + resL['customers']
|
||||
page = resL['pageNumber']
|
||||
print(f'总计请求{i}次,此次外呼记录数为{len(list)}')
|
||||
|
||||
load_data_to_db(list)
|
||||
detailDataList = []
|
||||
ids = []
|
||||
for data in dataList:
|
||||
j = 0
|
||||
for data in list:
|
||||
try:
|
||||
j=j+1
|
||||
for item in data:
|
||||
if item['key'] == -1:
|
||||
id=item['value']
|
||||
print(f'客户id:{id},开始请求数据')
|
||||
print(f'{j}. 客户id:{id},开始请求数据')
|
||||
resD = request_detail_signature_post(id)
|
||||
print(f'请求数据结束{id}')
|
||||
print(f'{j}. 请求数据结束{id}')
|
||||
if 'customer' in resD:
|
||||
ids.append(id)
|
||||
dataList = resD['customer']
|
||||
detailDataList.append(dataList)
|
||||
else:
|
||||
error = resD['error']
|
||||
print(f"请求客户资料详情(id:{id})失败,错误信息:{error}")
|
||||
print(f"{j}. 请求客户资料详情(id:{id})失败,错误信息:{error}")
|
||||
load_detail_exp_to_db(id)
|
||||
except Exception as e:
|
||||
print(f'请求客户资料详情(id:{id})异常,异常信息:{e}')
|
||||
print(f'{j}. 请求客户资料详情(id:{id})异常,异常信息:{e}')
|
||||
load_detail_exp_to_db(data['id'])
|
||||
print(f'444:{ids}')
|
||||
if len(ids) > 0:
|
||||
ids_str = [str(item) for item in ids]
|
||||
load_detail_data_to_db(ids_str,detailDataList)
|
||||
|
|
Loading…
Reference in New Issue