add workflow 天润Smart-ccc工单数据,dev
This commit is contained in:
parent
93ff830ba4
commit
0bf1a59741
|
@ -84,15 +84,15 @@ def request_data_signature_post():
|
||||||
jsonData = json.dumps(body)
|
jsonData = json.dumps(body)
|
||||||
print(f'body: {jsonData}')
|
print(f'body: {jsonData}')
|
||||||
dataReqL=requests.post(url,headers=header,data=jsonData)
|
dataReqL=requests.post(url,headers=header,data=jsonData)
|
||||||
|
resText = dataReqL.text
|
||||||
i = 0
|
i = 0
|
||||||
while 'error' in dataReqL and i < 5:
|
while 'error' in resText and i < 5:
|
||||||
|
print(f'请求工单列表失败,再次请求第{i+1}次')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
dataReqL=requests.post(url,headers=header,params=body)
|
dataReqL=requests.post(url,headers=header,params=body)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
resL=json.loads(dataReqL.text)
|
resL=json.loads(resText)
|
||||||
print(dataReqL)
|
print(dataReqL)
|
||||||
resL=json.loads(dataReqL.text)
|
|
||||||
return resL
|
return resL
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,13 +132,15 @@ def request_data_signature_get(id):
|
||||||
print(f'url: {url}')
|
print(f'url: {url}')
|
||||||
|
|
||||||
dataReqL=requests.get(url,headers={},params={})
|
dataReqL=requests.get(url,headers={},params={})
|
||||||
|
resText = dataReqL.text
|
||||||
i = 0
|
i = 0
|
||||||
while 'error' in dataReqL and i < 5:
|
while 'error' in resText and i < 5:
|
||||||
|
print(f'请求工单详情失败,再次请求第{i+1}次')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
dataReqL=requests.get(url,headers={},params={})
|
dataReqL=requests.get(url,headers={},params={})
|
||||||
i = i + 1
|
i = i + 1
|
||||||
resL=json.loads(dataReqL.text)
|
resD=json.loads(resText)
|
||||||
return resL
|
return resD
|
||||||
|
|
||||||
def load_detail_data_to_db(ids, dataList):
|
def load_detail_data_to_db(ids, dataList):
|
||||||
conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432")
|
conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432")
|
||||||
|
@ -157,21 +159,21 @@ def load_detail_data_to_db(ids, dataList):
|
||||||
print('加载数据结束:tickets_detail:获取工单详情')
|
print('加载数据结束:tickets_detail:获取工单详情')
|
||||||
|
|
||||||
def load_detail_exp_to_db(id):
|
def load_detail_exp_to_db(id):
|
||||||
print(f'添加查询工单异常记录:{id}')
|
try:
|
||||||
conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432")
|
print(f'添加查询工单异常记录:{id}')
|
||||||
print('数据库连接成功')
|
conn = psycopg2.connect(database="dataops_db", user="dbuser_dops", password="MIgTi3jA",host="172.17.0.8", port="5432")
|
||||||
dataId=str(uuid.uuid4())
|
print('数据库连接成功')
|
||||||
total=len(dataList)
|
dataId=str(uuid.uuid4())
|
||||||
print('临时id:'+dataId)
|
print('临时id:'+dataId)
|
||||||
json_object = json.dumps(dataList)
|
cur=conn.cursor()
|
||||||
idstr = ','.join(ids)
|
sql=" INSERT INTO data_api.cc_details_ids_exp (id,api_id,is_loaded,status,request_tm,execute_tm,remark) values (%s,%s,'0','0',current_timestamp(0),current_timestamp(0),'')"
|
||||||
cur=conn.cursor()
|
cur.execute(sql,[id, '6a977523d60f46788e6004549027bb8e'])
|
||||||
sql=" INSERT INTO data_api.cc_details_ids_exp (id,api_id,is_loaded,status,request_tm,execute_tm,remark) values (%s,%s,'0','0',current_timestamp(0),current_timestamp(0),'')"
|
conn.commit()
|
||||||
cur.execute(sql,[id, '6a977523d60f46788e6004549027bb8e'])
|
cur.close()
|
||||||
conn.commit()
|
conn.close()
|
||||||
cur.close()
|
print(f'添加查询工单异常记录:{id} 结束')
|
||||||
conn.close()
|
except Exception as e:
|
||||||
print(f'添加查询工单异常记录:{id} 结束')
|
print(f'添加查询工单异常记录:{id}失败, 错误信息:{e}')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(f'{formatted2_previous_hour(0)}开始请求工单信息')
|
print(f'{formatted2_previous_hour(0)}开始请求工单信息')
|
||||||
|
@ -189,6 +191,7 @@ if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
id = data['id']
|
id = data['id']
|
||||||
resD = request_data_signature_get(id)
|
resD = request_data_signature_get(id)
|
||||||
|
print(f"请求工单详情结果{resD}")
|
||||||
if 'error' in resD:
|
if 'error' in resD:
|
||||||
error = resD['error']
|
error = resD['error']
|
||||||
print(f"请求工单详情(id:{id})失败,错误信息:{error}")
|
print(f"请求工单详情(id:{id})失败,错误信息:{error}")
|
||||||
|
@ -198,7 +201,7 @@ if __name__ == "__main__":
|
||||||
dataList = resL['ticketDetail']
|
dataList = resL['ticketDetail']
|
||||||
detailDataList.append(dataList)
|
detailDataList.append(dataList)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'请求工单详情(id:{id})失败, 错误信息:{e}')
|
print(f'请求工单详情(id:{id})异常, )异常信息:{e}')
|
||||||
load_detail_exp_to_db(data['id'])
|
load_detail_exp_to_db(data['id'])
|
||||||
load_detail_data_to_db(ids,detailDataList)
|
load_detail_data_to_db(ids,detailDataList)
|
||||||
print(f'{formatted2_previous_hour(0)}请求工单信息结束')
|
print(f'{formatted2_previous_hour(0)}请求工单信息结束')
|
Loading…
Reference in New Issue