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