78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
|
|
import os,sys,time,shlex,subprocess,shutil,requests,json
|
|
import platform
|
|
if platform.system() == 'Windows':
|
|
sys.path.append('e:\\libs\\')
|
|
#sys.path.append('libs')
|
|
else:
|
|
sys.path.append('/data/deploy/make3d/make2/libs/')
|
|
import libs,config
|
|
def main(pid = 0):
|
|
print(f'开始时间-{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}')
|
|
if pid == 0:
|
|
#获取要处理PID的url
|
|
url = "https://repair.api.suwa3d.com/api/modelRepairOrder/getRepairOrderListByPriority"
|
|
#发起请求
|
|
res = requests.get(url)
|
|
print('res:', res.text)
|
|
if res.status_code != 200:
|
|
print('获取失败,程序退出')
|
|
return
|
|
res = json.loads(res.text)
|
|
pid = 0
|
|
try:
|
|
pid = res['data']['pid']
|
|
except Exception as e:
|
|
return 0
|
|
|
|
if pid == 0:
|
|
return 0
|
|
|
|
#调用oss下载功能,下载对应的文件
|
|
pathStr = os.path.join(config.workdir,str(pid)+"_ai")
|
|
libs.down_obj_from_oss_auto(str(pid),"auto",pathStr)
|
|
#检查是否存在产生的对应的文件
|
|
if not os.path.exists(os.path.join(pathStr,f'{pid}.obj')):
|
|
print(f"找不到{pid}obj文件")
|
|
return
|
|
|
|
if not os.path.exists(os.path.join(pathStr,f'{pid}.mtl')):
|
|
print(f"找不到{pid}mtl文件")
|
|
return
|
|
#下载完成后调用
|
|
os.system(f"python optimize_model.py -ip {pathStr}/{pid}.obj -op {pathStr}/{pid}_ai.obj")
|
|
#检查是否存在产生的对应的文件
|
|
if not os.path.exists(os.path.join(pathStr,f'{pid}_ai.obj')):
|
|
print(f"找不到{pid}ai_obj文件")
|
|
return
|
|
|
|
if not os.path.exists(os.path.join(pathStr,f'{pid}_ai.mtl')):
|
|
print(f"找不到{pid}ai_mtl文件")
|
|
return
|
|
|
|
#处理完成完后上传到oss指定目录
|
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/ai/fix_mesh/{pid}_ai.obj', os.path.join(pathStr,f'{pid}_ai.obj'))
|
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/ai/fix_mesh/{pid}_ai.mtl', os.path.join(pathStr,f'{pid}_ai.mtl'))
|
|
config.oss_bucket.put_object_from_file(f'objs/auto/{pid}/ai/fix_mesh/{pid}.jpg', os.path.join(pathStr,f'{pid}.jpg'))
|
|
#更新处理结果
|
|
url = "https://repair.api.suwa3d.com/api/modelRepairOrder/updateShootOrderBuildModelType?pid="+str(pid)
|
|
#发起请求
|
|
requests.get(url)
|
|
#移除文件夹
|
|
shutil.rmtree(pathStr)
|
|
print(f'结束时间-{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) == 2:
|
|
pid = sys.argv[1]
|
|
main(pid)
|
|
print(f"{pid}-处理结束")
|
|
else:
|
|
while True:
|
|
res = main()
|
|
if res == 0:
|
|
print("休眠60s")
|
|
time.sleep(60) |