regen_baic_task40.py
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""临时脚本:用最新代码直接调用 generate_result_excel 重导北汽专项任务 40(2026-09),
只读 task40 的已落库数据写结果表,不重新跑 D+ 取数(避免覆盖已填充的产值/订单)。
用法(在 data-process 目录):
PYTHONPATH="C:/Users/66/AppData/Roaming/Python/Python314/site-packages" C:/Python314/python.exe regen_baic_task40.py
"""
import sys
import os
import shutil
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
TASK_ID = 40
LOCAL_XLSX = os.path.join(HERE, 'outputs', f'baic_special_2026-09_task{TASK_ID}.xlsx')
from app import app, db
from models import DataProcessTask
import baic_special_processor as _bpmod
from baic_special_processor import BaicSpecialProcessor
_real_upload = _bpmod.upload_file
def _patched_upload(local_path, object_key=None):
try:
os.makedirs(os.path.dirname(LOCAL_XLSX), exist_ok=True)
shutil.copy(local_path, LOCAL_XLSX)
print(f"[regen] 已拷贝生成文件到本地预览: {LOCAL_XLSX}")
except Exception as e:
print(f"[regen] 本地拷贝失败: {e}")
try:
return _real_upload(local_path, object_key)
except Exception as e:
print(f"[regen] OSS 上传失败(本地副本已生成,可忽略): {e}")
return object_key or local_path
_bpmod.upload_file = _patched_upload
with app.app_context():
task = DataProcessTask.query.filter_by(id=TASK_ID).first()
if not task:
print("ERROR: task 40 not found")
sys.exit(1)
print(f"[regen] task {TASK_ID}: status={task.status}, month={task.month}")
url = BaicSpecialProcessor().generate_result_excel(task)
print(f"[regen] 完成, result url={url}")
print("[regen] done")