瀏覽代碼

更新脚本

deng.yinping 1 年之前
父節點
當前提交
bb199668e3
共有 3 個文件被更改,包括 11 次插入6 次删除
  1. 1 1
      requirements.txt
  2. 8 3
      services/mongodb_tools.py
  3. 2 2
      templates/index.html

+ 1 - 1
requirements.txt

@@ -1,3 +1,3 @@
-Flask==3.1.0
+Flask==3.0.3
 openpyxl==3.1.5
 pymongo==3.13.0

+ 8 - 3
services/mongodb_tools.py

@@ -23,10 +23,10 @@ class MongoDBTools:
                 
                 # 导出数据到excel
                 # 默认为按价格
-                file_name_pre = "static\quote_data\\price_";
+                file_name_pre = 'price_'
                 if query_entity.query_type == 2:
                     # 按时间
-                    file_name_pre = "static\quote_data\\time_";
+                    file_name_pre = 'time_'
                 if records is not None and len(records) > 0:
                     tools.export_to_excel(records, diff_records, query_entity.goods_code, file_name_pre)
                 print("time diff count: " + str(int(len(diff_records) /2)))
@@ -185,7 +185,12 @@ class MongoDBTools:
             wb.active = 1  # 激活 'Sheet2',index 从 0 开始,1 表示第二个工作表
                  
         # 保存 Excel 文件
-        file_name = file_name_pre +  goods_code + "_" + datetime.now().strftime("%Y%m%d%H%M%S") + ".xlsx"
+        # 目标文件的目录
+        dir_path = os.path.join('static', 'quote_data')
+        # 检查目录是否存在,如果不存在则创建
+        if not os.path.exists(dir_path):
+            os.makedirs(dir_path)
+        file_name = os.path.join(dir_path, file_name_pre +  goods_code + "_" + datetime.now().strftime("%Y%m%d%H%M%S") + ".xlsx")
         wb.save(file_name)
         
         print("quote date export to:" + file_name)

+ 2 - 2
templates/index.html

@@ -70,7 +70,7 @@
             <!-- 第四行:三个查询条件 -->
             <div class="form-row">
                 <div class="form-group">
-                    <label for="record_num">最新记录数:</label>
+                    <label for="record_num">记录数:</label>
                     <input type="text" id="record_num" name="record_num" value="{{ defaults['record_num'] }}" required>
                 </div>
                 <div class="form-group">
@@ -85,7 +85,7 @@
 
             <div class="form-row">
                 <div class="form-group">
-                    <label for="files_num">显示文件数:</label>
+                    <label for="files_num">文件数:</label>
                     <input type="text" id="files_num" name="files_num" value="{{ defaults['files_num'] }}" required>
                 </div>
                 <!-- 提交按钮 -->