建模程序 多个定时程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

70 lines
2.2 KiB

from flask import Flask, jsonify, request
import os
from flask_cors import CORS
app = Flask(__name__)
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
# 定义函数来递归遍历文件夹下的所有文件
def list_files(directory):
for root, dirs, files in os.walk(directory):
for file in files:
yield os.path.join(root, file)
# 更新数据
@app.route('/api/data/', methods=['GET'])
def update_data():
pid = request.args.get('pid')
angle = request.args.get('angle')
jump = request.args.get('jump')
if jump == "jump":
file_path = f'G:\obj_fix\print\wrong\{pid}_preview.png'
if not os.path.exists(file_path):
return "file not exists"
#重命名文件
new_file_path = f'G:\obj_fix\print\wrong\{pid}_preview_wait.png'
os.rename(file_path, new_file_path)
else:
if pid == "0":
return "pid is 0"
if str(angle[0]) == "0":
return "angle is 0"
file_path = f'G:\obj_fix\print\wrong\{pid}_preview.png'
if not os.path.exists(file_path):
return "file not exists"
#重命名文件
new_file_path = f'G:\obj_fix\print\wrong\{pid}_preview_{angle}.png'
os.rename(file_path, new_file_path)
#遍历 G:\obj_fix\print\wrong\ 文件夹下的所有文件
for file_path in list_files('G:\obj_fix\print\wrong'):
if "_preview.png" not in file_path:
continue
#获取pid 从 "G:\obj_fix\print\wrong\76289_preview_117.png" 中获取 "76289
pid = file_path.split('\\')[-1].split('_')[0]
return pid
# #组装链接
# url = f'https://mp.suwa3d.com/preview.html?platform=1&id={pid}&size=18cm_x1&angle=1#/'
# #将 url 写入文件
# with open('url.txt', 'a') as f:
# f.write(url + '\n')
#return jsonify({'pid': id1, 'angle': id2})
# for item in data:
# if item['id'] == data_id:
# item.update(request.get_json())
# return jsonify({'message': 'Data updated successfully'})
#return jsonify({'message': 'Data not found'}), 404
if __name__ == '__main__':
app.run(debug=True)