xiaowei-system/cache/patch_plan.py

28 lines
987 B
Python

#!/usr/bin/env python3
path = "/www/wwwroot/gaokao/gaokao-chat-server-v2.py"
with open(path, encoding="utf-8") as f:
lines = f.readlines()
# Find the body.get('subject') line inside prob_calc (after line 330)
inserted = False
for i, line in enumerate(lines):
if i < 330:
continue
if "body.get('subject'" in line and 'score = int' not in line:
print(f"Line {i+1}: {repr(line[:60])}")
indent = len(line) - len(line.lstrip())
ins = ' ' * indent + "# 表单科目映射到数据库yiyi表科目\n"
ins += ' ' * indent + "subject_map = {'文科': '历史类', '理科': '物理类'}\n"
ins += ' ' * indent + "subject = subject_map.get(subject, subject)\n"
lines.insert(i+1, ins)
print(f"Inserted 3 lines after line {i+1}")
inserted = True
break
if not inserted:
print("ERROR: line not found")
exit(1)
with open(path, 'w', encoding="utf-8") as f:
f.writelines(lines)
print("patched OK")