add workflow 天润Smart-ccc会话数据,dev
This commit is contained in:
parent
a50f5cd69c
commit
f621db7287
|
@ -72,9 +72,11 @@ def request_data_signature_get(scrollId):
|
|||
print(f'开始请求会话记录数据')
|
||||
url='https://api-bj.clink.cn/livechat/copy_chat_records'
|
||||
if scrollId is None:
|
||||
param={'Timestamp':current_time_utc,'Expires':86400,'date':formatted2_previous_date(0),'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','limit':100}
|
||||
# param={'Timestamp':current_time_utc,'Expires':86400,'date':formatted2_previous_date(0),'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','limit':100}
|
||||
param={'Timestamp':current_time_utc,'Expires':86400,'date':'20240801','AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','limit':100}
|
||||
else:
|
||||
param={'Timestamp':current_time_utc,'Expires':86400,'date':formatted2_previous_date(0),'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','limit':100,'scrollId':scrollId}
|
||||
# param={'Timestamp':current_time_utc,'Expires':86400,'date':formatted2_previous_date(0),'AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','limit':100,'scrollId':scrollId}
|
||||
param={'Timestamp':current_time_utc,'Expires':86400,'date':'20240801','AccessKeyId':'b17759d3a36fba9a2cf522fbf4cbf177','limit':100,'scrollId':scrollId}
|
||||
print(f'param: {param}')
|
||||
url_path = build_query_string(param)
|
||||
url_param = url_path
|
||||
|
@ -119,7 +121,7 @@ def request_detail_signature_get(id):
|
|||
resText = dataReqL.text
|
||||
i = 0
|
||||
while 'error' in resText and i < 5:
|
||||
print(f'请求会话记录失败,再次请求第{i+1}次')
|
||||
print(f'请求会话详情失败,再次请求第{i+1}次')
|
||||
time.sleep(1)
|
||||
dataReqL=requests.get(url,headers={},params={})
|
||||
resText = dataReqL.text
|
||||
|
@ -180,8 +182,10 @@ def load_detail_exp_to_db(id):
|
|||
|
||||
if __name__ == "__main__":
|
||||
print(f'{formatted2_previous_hour(0)}开始请求会话信息')
|
||||
hour_delta = 48
|
||||
previous_time = previous_hour_timestamp(hour_delta)
|
||||
resL = request_data_signature_get(None)
|
||||
print(resL)
|
||||
# print(resL)
|
||||
if 'error' in resL:
|
||||
error = resL['error']
|
||||
print(f'请求会话列表失败,失败原因:{error}')
|
||||
|
@ -189,7 +193,9 @@ if __name__ == "__main__":
|
|||
list = resL['records']
|
||||
scrollId = resL['scrollId']
|
||||
nextList = []
|
||||
i = 1
|
||||
while scrollId is not None:
|
||||
i = i+1
|
||||
resN = request_data_signature_get(scrollId)
|
||||
if 'error' in resN:
|
||||
error = resL['error']
|
||||
|
@ -202,18 +208,29 @@ if __name__ == "__main__":
|
|||
list = list + nextList
|
||||
if len(nextList) < 100:
|
||||
break
|
||||
load_data_to_db(list)
|
||||
print(f'records会话记录数为:{len(list)}, 共请求{i}次会话')
|
||||
# load_data_to_db(list)
|
||||
detailDataList = []
|
||||
actList = []
|
||||
ids = []
|
||||
j = 0
|
||||
for data in list:
|
||||
try:
|
||||
id = data['mainUniqueId']
|
||||
startTime = data['startTime']
|
||||
endTime = data['endTime']
|
||||
print(f'对比时间:{previous_time},数据开始时间:{startTime},会话结束时间:{endTime}')
|
||||
if startTime < previous_time and endTime < previous_time:
|
||||
print(f'该id不在采集{hour_delta}个小时内,不做采集{id}')
|
||||
continue
|
||||
actList.append(data)
|
||||
j = j + 1
|
||||
print(f'{j}. 开始请求会话详情数据:{id}')
|
||||
resD = request_detail_signature_get(id)
|
||||
#print(f"请求工单详情结束")
|
||||
if 'records' in resD:
|
||||
ids.append(id)
|
||||
dataList = resD['records']
|
||||
|
||||
# detailDataList.append(dataList)
|
||||
detailDataList = detailDataList+dataList
|
||||
else:
|
||||
|
@ -223,8 +240,10 @@ if __name__ == "__main__":
|
|||
except Exception as e:
|
||||
print(f'请求会话详情(id:{id})异常, )异常信息:{e}')
|
||||
load_detail_exp_to_db(data['id'])
|
||||
print(f'实际加载{j}-{len(actList)-{len(detailDataList)}}条记录')
|
||||
load_data_to_db(actList)
|
||||
if len(ids) > 0:
|
||||
ids_str = [str(item) for item in ids]
|
||||
print(f'会话详情{ids_str}')
|
||||
# print(f'会话详情{ids_str}')
|
||||
load_detail_data_to_db(ids_str,detailDataList)
|
||||
print(f'{formatted2_previous_hour(0)}请求会话信息结束')
|
||||
print(f'{formatted2_previous_hour(0)}请求会话信息结束')
|
Loading…
Reference in New Issue