''' Author: deng.yinping deng.yinping@muchinfo.cn Date: 2024-11-28 15:57:05 LastEditors: deng.yinping deng.yinping@muchinfo.cn LastEditTime: 2024-11-29 11:01:44 FilePath: \py_quote\app.py Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE ''' from flask import Flask, render_template, request, redirect, url_for import os import datetime from services.mongodb_tools import MongoDBTools from services.quote_query_entity import QuoteQueryEntity from flask import Flask, render_template, request from app_config import UPLOAD_FOLDER, SERVICE_PORT, DEFAULT_PARAM app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER # 从配置文件中读取配置 app.config['SERVER_PORT'] = SERVICE_PORT # 可以在配置文件中设置这个值 @app.route('/', methods=['GET', 'POST']) def index(): file_list = [] if request.method == 'POST': # 查询mongodb数据并生成excel query_entity = QuoteQueryEntity() query_entity.host = request.form['host'] query_entity.port = int(request.form['port']) query_entity.username = request.form['username'] query_entity.password = request.form['password'] query_entity.db_name = request.form['db_name'] query_entity.col_name = request.form['col_name'] query_entity.goods_code = request.form['goods_code'] query_entity.query_type = int(request.form['query_type']) query_entity.start_time = request.form['start_time'].replace("T", " ") query_entity.end_time = request.form['end_time'].replace("T", " ") query_entity.diff_value = int(request.form['diff_value']) query_entity.record_num = int(request.form['record_num']) query_entity.files_num = int(request.form['files_num']) MongoDBTools.query_mongodb_data(query_entity) file_list = MongoDBTools.read_files(app.config['UPLOAD_FOLDER'], '.xlsx', query_entity.files_num) return render_template('index.html', defaults=query_entity, file_list=file_list) else: # 默认查询条件 file_list = MongoDBTools.read_files(app.config['UPLOAD_FOLDER'], '.xlsx', DEFAULT_PARAM.files_num) return render_template('index.html', defaults=DEFAULT_PARAM, file_list=file_list) @app.route('/open_file/') def open_file(filename): # 返回文件内容 return redirect(url_for('static', filename=f'quote_data/{filename}')) if __name__ == '__main__': app.run(host='0.0.0.0', port=app.config['SERVER_PORT'])